Skip to content

Commit

Permalink
fix freeze on @threads loop exit
Browse files Browse the repository at this point in the history
Closes #45626, hopefully.
  • Loading branch information
vtjnash committed Jul 1, 2022
1 parent bd7bd5e commit 86d8d8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void JL_UV_LOCK(void)
}
else {
jl_atomic_fetch_add_relaxed(&jl_uv_n_waiters, 1);
jl_fence(); // [^store_buffering_1]
jl_wake_libuv();
JL_LOCK(&jl_uv_mutex);
jl_atomic_fetch_add_relaxed(&jl_uv_n_waiters, -1);
Expand Down
7 changes: 6 additions & 1 deletion src/partr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ static const int16_t sleeping = 1;
// * Enqueuer:
// * 2: `jl_atomic_load_relaxed(&ptls->sleep_check_state)` in `jl_wakeup_thread` returns `not_sleeping`
// i.e., the dequeuer misses the enqueue and enqueuer misses the sleep state transition.

// and
// * Enqueuer:
// * 1: `jl_atomic_store_relaxed(jl_uv_n_waiters, 1)` in `JL_UV_LOCK`
// * Dequeuer:
// * 2: `jl_atomic_load_relaxed(jl_uv_n_waiters)` in `jl_task_get_next` returns `0`
// i.e., the dequeuer misses the `n_waiters` is set and enqueuer misses the uv_stop flag (in signal_async) transition to cleared

JULIA_DEBUG_SLEEPWAKE(
uint64_t wakeup_enter;
Expand Down

0 comments on commit 86d8d8f

Please sign in to comment.