[Issue 20680] core.thread.Thread leaks OS handle when not joined
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 25 11:01:56 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20680
Sebastiaan Koppe <mail at skoppe.eu> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mail at skoppe.eu
OS|Windows |All
--- Comment #1 from Sebastiaan Koppe <mail at skoppe.eu> ---
This is the case as well under Linux.
With GDB attached I have put a breakpoint at the core.thread.osthread.Thread's
destructor and confirmed it doesn't get run (I spawned 100k threads and let
them run till finish).
As a workaround I am calling `pthread_detach(pthread_self);` right before the
thread terminates. This is not a good solution though since the Thread's
destructor (if it did ran), would also call pthread_detach, which results in
undefined behaviour.
Better would be to do a thread_detachThis as well, since that will cause a
different branch in the Thread's destructor and avoid the call to
pthread_detach.
Sadly, using thread_detachThis and the pthread_detach I get spurious crashes in
std.concurrency's tls module teardown (sometimes).
--
More information about the Digitalmars-d-bugs
mailing list