Comment #0 by dlang-bugzilla — 2015-09-17T01:05:17Z
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).
Comment #1 by dlang-bugzilla — 2015-09-17T01:09:37Z
Alternatively this could go into std.process, alongside thisProcessID.
Comment #2 by issues.dlang — 2015-09-17T09:49:08Z
I would think that the most natural thing to do (and what most folks would likely look for) would be a static function/property on core.thread.Thread - e.g. Thread.currThreadID - since that's where the thread stuff is.
Comment #3 by schveiguy — 2015-09-17T15:07:56Z
What is the use case for this? Why doesn't Thread.getThis suffice?
Comment #4 by dlang-bugzilla — 2015-09-17T15:51:45Z
https://github.com/D-Programming-Language/druntime/pull/1388https://github.com/D-Programming-Language/phobos/pull/3654
(In reply to Jonathan M Davis from comment #2)
> I would think that the most natural thing to do (and what most folks would
> likely look for) would be a static function/property on core.thread.Thread -
> e.g. Thread.currThreadID - since that's where the thread stuff is.
Then we would have three conventions for such functions.
Currently, there is core.thread.getpid and std.process.thisProcessID. Introducing something that's unlike neither of these would be very inconsistent.
(In reply to Steven Schveighoffer from comment #3)
> What is the use case for this? Why doesn't Thread.getThis suffice?
Thread.getThis:
1. Returns a pointer, not the OS identifier. The pointer cannot be unique per-process (esp. in the case of multiple D runtimes).
2. Requires that the current thread is registered with the D runtime. If it isn't, it returns null.
Comment #5 by github-bugzilla — 2015-09-27T12:38:18Z