Skip to content

Commit

Permalink
Take the thread lock when setting a thread's "getThis" value to make …
Browse files Browse the repository at this point in the history
…sure all

threads are scanned for alternative GC mechanisms.
  • Loading branch information
schveiguy committed Feb 3, 2025
1 parent d8bce50 commit ca41cdc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions runtime/druntime/src/core/thread/osthread.d
Original file line number Diff line number Diff line change
Expand Up @@ -2489,8 +2489,13 @@ else version (Posix)
obj.initDataStorage();

atomicStore!(MemoryOrder.raw)(obj.m_isRunning, true);
Thread.setThis(obj); // allocates lazy TLS (see Issue 11981)
Thread.add(obj); // can only receive signals from here on

// ensure we can't run a GC cycle between these 2 lines.
Thread.slock.lock_nothrow();
Thread.setThis(obj); // allocates lazy TLS (see Issue 11981)
Thread.add(obj); // can only receive signals from here on
Thread.slock.unlock_nothrow();

scope (exit)
{
Thread.remove(obj);
Expand Down

0 comments on commit ca41cdc

Please sign in to comment.