Skip to content

Commit

Permalink
fixup! threads: avoid deadlock from recursive lock acquire
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Dec 1, 2020
1 parent dbdc46b commit fb9cfe9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,13 @@ JL_DLLEXPORT void jl_switch(void)
jl_error("cannot switch to task running on another thread");
}

// Store old values on the stack
// Store old values on the stack and reset
sig_atomic_t defer_signal = ptls->defer_signal;
int8_t gc_state = jl_gc_unsafe_enter(ptls);
size_t world_age = ptls->world_age;
int finalizers_inhibited = ptls->finalizers_inhibited;
ptls->world_age = 0;
ptls->finalizers_inhibited = 0;

#ifdef ENABLE_TIMINGS
jl_timing_block_t *blk = ptls->timing_stack;
Expand All @@ -538,7 +540,9 @@ JL_DLLEXPORT void jl_switch(void)
#endif

// Pop old values back off the stack
assert(ct == ptls->current_task);
assert(ct == ptls->current_task &&
0 == ptls->world_age &&
0 == ptls->finalizers_inhibited);
ptls->world_age = world_age;
ptls->finalizers_inhibited = finalizers_inhibited;

Expand Down Expand Up @@ -801,6 +805,7 @@ STATIC_OR_JS void NOINLINE JL_NORETURN start_task(void)
jl_ptls_t ptls = jl_get_ptls_states();
jl_task_t *t = ptls->current_task;
jl_value_t *res;
assert(ptls->finalizers_inhibited == 0);

#ifdef MIGRATE_TASKS
jl_task_t *pt = ptls->previous_task;
Expand Down

0 comments on commit fb9cfe9

Please sign in to comment.