[Issue 21784] New: joining a detached thread results in segfault.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 30 10:04:14 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21784

          Issue ID: 21784
           Summary: joining a detached thread results in segfault.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: omerfirmak at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list