Skip to content

Commit

Permalink
Merge pull request #9 from jacob-hughes/tls_null_check
Browse files Browse the repository at this point in the history
Add a null check before pushing TLS roots on scheduling thread
  • Loading branch information
ltratt authored Jan 18, 2024
2 parents eefddc3 + 3abed8b commit 53239d3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pthread_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,15 @@ GC_INNER void GC_push_all_stacks(void)
// We need to push the TLS rootset for the current thread (i.e. the thread
// which invoked GC). The TLS rootset for all other threads is pushed from
// inside their suspend handler.
GC_self_thread_inner() -> crtn -> tls_rootset = GC_tls_rootset();
//
// However, a GC can be scheduled by the current thread while it is being
// registered. This is fine because it won't contain any roots yet -- but it
// does mean that the thread might not have setup a context yet. So we must
// perform null check.
GC_thread me = GC_self_thread_inner();
if (me != NULL) {
me -> crtn -> tls_rootset = GC_tls_rootset();
}

GC_ASSERT(I_HOLD_LOCK());
GC_ASSERT(GC_thr_initialized);
Expand Down

0 comments on commit 53239d3

Please sign in to comment.