Get parent Tid of a thread?
Ali Çehreli
acehreli at yahoo.com
Wed Jun 29 15:12:17 PDT 2011
On Wed, 29 Jun 2011 22:59:47 +0200, 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 }
Just pass it in as the first parameter:
import std.stdio;
import std.concurrency;
void workerThread(Tid owner)
{
// ...
writeln("worker's thisTid: ", &thisTid);
assert(owner != thisTid);
}
void main()
{
writeln("owner's thisTid : ", &thisTid);
Tid worker = spawn(&workerThread, thisTid);
}
Interestingly the two variables will have the same address but they are
not equal as the assert above passes:
owner's thisTid : 46B58C
worker's thisTid: 46B58C
Ali
More information about the Digitalmars-d-learn
mailing list