Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 2dede46

Browse files
tim-dlangdlang-bot
authored andcommitted
Improve documentation for thread_attachThis / thread_detachThis
The function rt_moduleTlsDtor must be called before thread_detachThis, because the memory referenced by thread-local storage could be freed by the GC after thread_detachThis. A thread-local static destructor called by rt_moduleTlsDtor could access the already freed memory. Calling rt_moduleTlsDtor first prevents this. Links in core.memory to thread_attachThis / thread_detachThis did not work and are fixed now. Also added links between thread_attachThis and thread_detachThis.
1 parent 0c2400e commit 2dede46

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/core/memory.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
$(LI Maintain another reference to that same data in another thread that the
3232
GC does know about.)
3333
$(LI Disable GC collection cycles while that thread is active with $(LREF disable)/$(LREF enable).)
34-
$(LI Register the thread with the GC using $(REF thread_attachThis, core,thread)/$(REF thread_detachThis, core,thread).)
34+
$(LI Register the thread with the GC using $(REF thread_attachThis, core,thread,osthread)/$(REF thread_detachThis, core,thread,threadbase).)
3535
)
3636
)
3737
)

src/core/thread/osthread.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,9 @@ private extern (D) ThreadBase attachThread(ThreadBase _thisThread) @nogc nothrow
12671267
* must be called after thread_attachThis:
12681268
*
12691269
* extern (C) void rt_moduleTlsCtor();
1270+
*
1271+
* See_Also:
1272+
* $(REF thread_detachThis, core,thread,threadbase)
12701273
*/
12711274
extern(C) Thread thread_attachThis()
12721275
{

src/core/thread/threadbase.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,13 @@ package ThreadT thread_attachThis_tpl(ThreadT)()
816816
*
817817
* NOTE: This routine does not run thread-local static destructors when called.
818818
* If full functionality as a D thread is desired, the following function
819-
* must be called after thread_detachThis, particularly if the thread is
819+
* must be called before thread_detachThis, particularly if the thread is
820820
* being detached at some indeterminate time before program termination:
821821
*
822822
* $(D extern(C) void rt_moduleTlsDtor();)
823+
*
824+
* See_Also:
825+
* $(REF thread_attachThis, core,thread,osthread)
823826
*/
824827
extern (C) void thread_detachThis() nothrow @nogc
825828
{

0 commit comments

Comments
 (0)