www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21784] New: joining a detached thread results in segfault.


          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 puremagic.com
          Reporter: omerfirmak gmail.com

import core.thread;
import core.sync.semaphore;

__gshared Semaphore sem;

void thread_main ()

void main()
    auto th = new Thread(&thread_main);
    sem = new Semaphore();
    while (th.isRunning()) {}
    destroy(th); // force detach

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.

Mar 30 2021