Signal td->free_cond with the associated mutex held
authorBart Van Assche <bart.vanassche@wdc.com>
Fri, 16 Mar 2018 15:38:34 +0000 (08:38 -0700)
committerBart Van Assche <bart.vanassche@wdc.com>
Fri, 16 Mar 2018 19:46:05 +0000 (12:46 -0700)
commit564de8d10188bc855343f915ca9fdbbf9c722465
treeeefc344dfdc0512dd75047a17bbb9986a1dedb9b
parent93b45bb2e4c511f2d9a9a7552d74e1d921b0bf76
Signal td->free_cond with the associated mutex held

Calling pthread_cond_signal() or pthread_cond_broadcast() without
holding the associated mutex can lead to missed wakeups. Hence ensure
that td->io_u_lock is held around pthread_cond_signal(&td->free_cond)
calls. A quote from the POSIX spec
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_broadcast.html):

"The pthread_cond_broadcast() or pthread_cond_signal() functions may be
called by a thread whether or not it currently owns the mutex that
threads calling pthread_cond_wait() or pthread_cond_timedwait() have
associated with the condition variable during their waits; however, if
predictable scheduling behavior is required, then that mutex shall be
locked by the thread calling pthread_cond_broadcast() or
pthread_cond_signal()."

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
io_u.c
verify.c