Skip to content

Commit 971b759

Browse files
committed
Avoid dead lock due to ti_threadgroup_join
1 parent 6c4f3e3 commit 971b759

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/threading.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ JL_DLLEXPORT void *jl_threadgroup(void) { return (void *)tgworld; }
422422
// and run it in all threads
423423
JL_DLLEXPORT jl_value_t *jl_threading_run(jl_function_t *f, jl_svec_t *args)
424424
{
425+
// unmanaged safe
425426
#if PROFILE_JL_THREADING
426427
uint64_t tstart = rdtsc();
427428
#endif
@@ -433,6 +434,7 @@ JL_DLLEXPORT jl_value_t *jl_threading_run(jl_function_t *f, jl_svec_t *args)
433434
JL_TYPECHK(jl_threading_run, function, (jl_value_t*)f);
434435
JL_TYPECHK(jl_threading_run, simplevector, (jl_value_t*)args);
435436

437+
int8_t gc_state = jl_gc_unsafe_enter();
436438
JL_GC_PUSH2(&argtypes, &fun);
437439
if (jl_svec_len(args) == 0)
438440
argtypes = (jl_tupletype_t*)jl_typeof(jl_emptytuple);
@@ -470,15 +472,18 @@ JL_DLLEXPORT jl_value_t *jl_threading_run(jl_function_t *f, jl_svec_t *args)
470472
user_ticks[ti_tid] += (trun - tfork);
471473
#endif
472474

475+
jl_gc_state_set(3, 0);
473476
// wait for completion (TODO: nowait?)
474477
ti_threadgroup_join(tgworld, ti_tid);
478+
jl_gc_state_set(0, 3);
475479

476480
#if PROFILE_JL_THREADING
477481
uint64_t tjoin = rdtsc();
478482
join_ticks[ti_tid] += (tjoin - trun);
479483
#endif
480484

481485
JL_GC_POP();
486+
jl_gc_unsafe_leave(gc_state);
482487

483488
return tw->ret;
484489
}

0 commit comments

Comments
 (0)