Get parent Tid of a thread?

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 29 15:12:14 PDT 2011


On 2011-06-29 13:59, Andrej Mitrovic wrote:
> Is there any way a newly spawned thread can get the Tid of the thread
> that spawned it, basically its parent? I'd prefer that over using
> this:
> 
> __gshared mainThread; // so workThread can access it
> 
> {
> mainThread = thisTid();
> auto workThread = spawn(&MidiThread); // local
> }

Usually what you do is give the parent's Tid as an argument to spawn. So, in 
this case, MidiThread would have a parameter of type Tid, and you'd change 
your code to

auto spawnedTid = spawn(&MidiThread, thisTid());

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list