digitalmars.D.learn - Get parent Tid of a thread?
- Andrej Mitrovic (8/8) Jun 29 2011 Is there any way a newly spawned thread can get the Tid of the thread
- Simen Kjaeraas (7/15) Jun 29 2011 std.concurrency actually has a thread-local variable called 'owner',
- Andrej Mitrovic (1/1) Jun 29 2011 I've filed it http://d.puremagic.com/issues/show_bug.cgi?id=6224
- Ali =?iso-8859-1?q?=C7ehreli?= (20/28) Jun 29 2011 Just pass it in as the first parameter:
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
}
Jun 29 2011
On Wed, 29 Jun 2011 22:59:47 +0200, Andrej Mitrovic
<andrej.mitrovich gmail.com> 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
}
std.concurrency actually has a thread-local variable called 'owner',
which is exactly what you want. However, it is private.
This may very well be worth an enhancement request.
--
Simen
Jun 29 2011
I've filed it http://d.puremagic.com/issues/show_bug.cgi?id=6224
Jun 29 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
Jun 29 2011









Andrej Mitrovic <andrej.mitrovich gmail.com> 