[Issue 15076] New: Get ID of current thread

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Sep 16 18:05:17 PDT 2015


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 at puremagic.com
          Reporter: thecybershadow at 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).

--


More information about the Digitalmars-d-bugs mailing list