druntime: why do we call pthread_detach on our main thread?
Johan
j at j.nl
Sat Jul 25 23:58:51 UTC 2020
Hi all,
Who knows all about druntime's thread handling?
ThreadSanitizer is crashing upon the detaching of the main thread
upon program termination [1]:
rt_term --> thread_term --> Thread.sm_main.__dtor() -->
pthread_detach( m_addr )
then ThreadSanitizer hooks into pthread_detach and doesn't see
the threadID in its database.
I'm wondering if we need this call at all in druntime?
What is the purpose of detaching our main thread?
This diff fixes the problem, and I don't see adverse effects
yet...
diff --git a/src/core/thread/osthread.d
b/src/core/thread/osthread.d
index b23cba7..40f8a55 100644
--- a/src/core/thread/osthread.d
+++ b/src/core/thread/osthread.d
@@ -727,7 +727,10 @@ class Thread
}
else version (Posix)
{
- pthread_detach( m_addr );
+ if (!isMainThread())
+ {
+ pthread_detach( m_addr );
+ }
m_addr = m_addr.init;
}
version (Darwin)
Thanks,
Johan
[1] https://github.com/ldc-developers/ldc/issues/3519
More information about the Digitalmars-d
mailing list