A suggestion for avoiding potential races with is_paused
Dear developers, in below code, should the lock paused in do_resume be released after is_paused=false? In do_pause
, is_paused=true
is guarded by the lock but not in do_resume
.
https://github.com/libguestfs/nbdkit/blob/master/filters/pause/pause.c#L146-L174
static void
do_pause (void)
{
...;
pthread_mutex_lock (&paused);
is_paused = true;
...;
while (count_requests > 0)
pthread_cond_wait (&count_cond, &count_lock);
nbdkit_debug ("pause: paused");
}
static void
do_resume (void)
{
if (!is_paused) return;
/* Release the worker threads. */
pthread_mutex_unlock (&paused);
is_paused = false;
nbdkit_debug ("pause: resumed");
}