Cannot get thread ID with Thread.getThis() in specific callback functions on Windows

Max Samukha spambox at d-coding.com
Tue Dec 7 03:02:18 PST 2010


On 12/06/2010 10:47 PM, Mike Parker wrote:
> On 12/7/2010 2:10 AM, Haruki Shigemori wrote:
>> (2010/12/06 16:59), Denis Koroskin wrote:
>>> Because D runtime doesn't know about the newly created thread, and
>>> static constructors weren't called. Try calling the following in your
>>> callbacks:
>>>
>>> if (Thread.getThis() is null) thread_attachThis(); // if
>>> (dont_know_about_this_thread) initialize_it();
>>
>> Wow... Is this D's design?
>> I want phobos or druntime to take care of this problem.
>> Is it difficult?
>
> The problem is that the thread is created outside of druntime, internal
> to the Windows API. How is druntime to know about it unless you tell it?

This could be done by installing a kernel driver that would use 
PsSetCreateThreadNotifyRoutine (if I remember the name correctly) to 
register a callback that would use an IPC mechanism to notify druntime 
about new threads created by the system. Chances that this approach will 
be adopted by druntime are less than zero.


More information about the Digitalmars-d mailing list