Skip to content

Commit 61c0b41

Browse files
make Ctrl-C during sleeping work better (#47901) (#47912)
fixes #46635 co-authored-by: Jameson Nash <[email protected]> (cherry picked from commit b6f32bc) Co-authored-by: Jeff Bezanson <[email protected]>
1 parent 3d1e89d commit 61c0b41

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/partr.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,14 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *trypoptask, jl_value_t *q)
552552
JL_UV_LOCK(); // jl_mutex_lock(&jl_uv_mutex);
553553
}
554554
if (uvlock) {
555-
int active = 1;
556-
// otherwise, we block until someone asks us for the lock
557-
uv_loop_t *loop = jl_global_event_loop();
558-
while (active && may_sleep(ptls)) {
559-
if (jl_atomic_load_relaxed(&jl_uv_n_waiters) != 0)
560-
// but if we won the race against someone who actually needs
561-
// the lock to do real work, we need to let them have it instead
562-
break;
555+
int enter_eventloop = may_sleep(ptls);
556+
int active = 0;
557+
if (jl_atomic_load_relaxed(&jl_uv_n_waiters) != 0)
558+
// if we won the race against someone who actually needs
559+
// the lock to do real work, we need to let them have it instead
560+
enter_eventloop = 0;
561+
if (enter_eventloop) {
562+
uv_loop_t *loop = jl_global_event_loop();
563563
loop->stop_flag = 0;
564564
JULIA_DEBUG_SLEEPWAKE( ptls->uv_run_enter = cycleclock() );
565565
active = uv_run(loop, UV_RUN_ONCE);
@@ -572,11 +572,11 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *trypoptask, jl_value_t *q)
572572
// that just wanted to steal libuv from us. We will just go
573573
// right back to sleep on the individual wake signal to let
574574
// them take it from us without conflict.
575-
if (!may_sleep(ptls)) {
575+
if (active || !may_sleep(ptls)) {
576576
start_cycles = 0;
577577
continue;
578578
}
579-
if (!jl_atomic_load_relaxed(&_threadedregion) && active && ptls->tid == 0) {
579+
if (!enter_eventloop && !jl_atomic_load_relaxed(&_threadedregion) && ptls->tid == 0) {
580580
// thread 0 is the only thread permitted to run the event loop
581581
// so it needs to stay alive, just spin-looping if necessary
582582
if (jl_atomic_load_relaxed(&ptls->sleep_check_state) != not_sleeping) {

0 commit comments

Comments
 (0)