Skip to content

Commit e329688

Browse files
committed
create phantom task for GC threads (JuliaLang#53815)
1 parent 54614fd commit e329688

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/partr.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ void jl_gc_mark_threadfun(void *arg)
122122
// initialize this thread (set tid and create heap)
123123
jl_ptls_t ptls = jl_init_threadtls(targ->tid);
124124

125+
void *stack_lo, *stack_hi;
126+
jl_init_stack_limits(0, &stack_lo, &stack_hi);
127+
// warning: this changes `jl_current_task`, so be careful not to call that from this function
128+
jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi);
129+
JL_GC_PROMISE_ROOTED(ct);
130+
125131
// wait for all threads
126132
jl_gc_state_set(ptls, JL_GC_STATE_WAITING, 0);
127133
uv_barrier_wait(targ->barrier);
@@ -147,6 +153,12 @@ void jl_gc_sweep_threadfun(void *arg)
147153
// initialize this thread (set tid and create heap)
148154
jl_ptls_t ptls = jl_init_threadtls(targ->tid);
149155

156+
void *stack_lo, *stack_hi;
157+
jl_init_stack_limits(0, &stack_lo, &stack_hi);
158+
// warning: this changes `jl_current_task`, so be careful not to call that from this function
159+
jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi);
160+
JL_GC_PROMISE_ROOTED(ct);
161+
150162
// wait for all threads
151163
jl_gc_state_set(ptls, JL_GC_STATE_WAITING, 0);
152164
uv_barrier_wait(targ->barrier);

src/task.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
16851685
JL_GC_PROMISE_ROOTED(ct);
16861686
jl_set_pgcstack(&ct->gcstack);
16871687
assert(jl_current_task == ct);
1688+
assert(jl_current_task->ptls == ptls);
16881689

16891690
#ifdef _COMPILER_TSAN_ENABLED_
16901691
ct->ctx.tsan_state = __tsan_get_current_fiber();

0 commit comments

Comments
 (0)