Bug 21784 – joining a detached thread results in segfault.
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-03-30T10:04:14Z
Last change time
2021-04-18T14:24:33Z
Keywords
pull
Assigned to
No Owner
Creator
omerfirmak
Comments
Comment #0 by omerfirmak — 2021-03-30T10:04:14Z
import core.thread;
import core.sync.semaphore;
__gshared Semaphore sem;
void thread_main ()
{
sem.notify();
}
void main()
{
auto th = new Thread(&thread_main);
sem = new Semaphore();
th.start();
sem.wait();
while (th.isRunning()) {}
destroy(th); // force detach
th.join();
}
Above piece of code will segfault since the dtor of the Thread will reset m_addr and Thread.join() will pass that null value to phread_join() without checking if it is valid.
Comment #1 by dlang-bot — 2021-03-30T10:05:14Z
@omerfirmak updated dlang/druntime pull request #3418 "Allow detached threads to be joined" fixing this issue:
- Fix Issue 21784: Allow detached threads to be joined
This is useful when a thread terminates before the
caller is able to join().
https://github.com/dlang/druntime/pull/3418
Comment #2 by dlang-bot — 2021-03-30T10:53:51Z
dlang/druntime pull request #3418 "Fix Issue 21784: Allow detached threads to be joined" was merged into stable:
- b301faf42df1bfab60ada38473dd46000c1fdf66 by Ömer Faruk Irmak:
Fix Issue 21784: Allow detached threads to be joined
This is useful when a thread terminates before the
caller is able to join().
https://github.com/dlang/druntime/pull/3418
Comment #3 by dlang-bot — 2021-04-18T14:24:33Z
dlang/druntime pull request #3434 "merge stable" was merged into master:
- c5eb299128d7614e18ee2e2366005843dbeb0c6b by Ömer Faruk Irmak:
Fix Issue 21784: Allow detached threads to be joined
This is useful when a thread terminates before the
caller is able to join().
https://github.com/dlang/druntime/pull/3434