diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-07-29 14:28:51 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-07-29 14:28:51 -0400 |
commit | ead25f6c6bad5c65dbbe9c887b29a44dc3bf1bb8 (patch) | |
tree | 7b65f647aa6ebc4a7c673bc8ef6a4f366ad57a14 /libdimension/future.c | |
parent | 000f928e22bd223d1f1aa2d783ee0b30fe295df7 (diff) | |
download | dimension-ead25f6c6bad5c65dbbe9c887b29a44dc3bf1bb8.tar.xz |
future: Fix race with two pausing threads.
Diffstat (limited to 'libdimension/future.c')
-rw-r--r-- | libdimension/future.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/libdimension/future.c b/libdimension/future.c index ef3f5e2..8133812 100644 --- a/libdimension/future.c +++ b/libdimension/future.c @@ -164,10 +164,9 @@ dmnsn_future_pause(dmnsn_future *future) while (future->nrunning < future->nthreads) { dmnsn_cond_wait_safely(&future->all_running_cond, &future->mutex); } - if (future->npaused++ == 0) { - while (future->nrunning > 0) { - dmnsn_cond_wait_safely(&future->none_running_cond, &future->mutex); - } + ++future->npaused; + while (future->nrunning > 0) { + dmnsn_cond_wait_safely(&future->none_running_cond, &future->mutex); } dmnsn_unlock_mutex(&future->mutex); } @@ -177,8 +176,7 @@ void dmnsn_future_resume(dmnsn_future *future) { dmnsn_lock_mutex(&future->mutex); - dmnsn_assert(future->npaused > 0, - "dmnsn_future_resume() without matching dmnsn_future_pause()"); + dmnsn_assert(future->npaused > 0, "dmnsn_future_resume() without matching dmnsn_future_pause()"); if (--future->npaused == 0) { dmnsn_cond_broadcast(&future->resume_cond); } |