www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15076] New: Get ID of current thread

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

          Issue ID: 15076
           Summary: Get ID of current thread
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com

core.thread is missing a function to get the ID of the current thread. getpid
is insufficient, as even on POSIX it will return the same value for all
threads:

///////// test.d /////////
import core.thread;
import std.stdio;

void main()
{
    writeln(getpid());
    new Thread({
        writeln(getpid());
    }).start();
}
//////////////////////////

Essentially, it should be GetCurrentThreadId() on Windows and pthread_self() on
POSIX (same logic as for initializing Thread.m_addr).

--
Sep 16 2015