[Issue 6224] New: Make a read-only public ownerTid property for std.concurrency

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 29 14:44:26 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6224

           Summary: Make a read-only public ownerTid property for
                    std.concurrency
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-06-29 14:39:31 PDT ---
I need a way to get the Tid of the thread that spawned the current thread.

I've had this kind of bug creep into my code:

__gshared Tid mainThread;
__gshared Tid workThread;

workThreadFoo()
{
   workThread.send("data");  // Bug: Meant to be mainThread.send
}

mainThreadFoo()
{
    mainThread = thisTid;
    workThread = spawn(&workThreadFoo);
}

This can be taken care of with this workaround:

workThreadFoo()
{
   Tid mainThread = receiveOnly!Tid();
   // workThread.send("data");  // Now this can't creep in

   mainThread.send("data");     // correct
}

mainThreadFoo()
{
    Tid workThread = spawn(&workThreadFoo);
    workThread.send(thisTid);
}

But it would be better if I didn't have to take this extra step and instead
used:

workThreadFoo()
{
   Tid mainThread = thisTid.ownerTid;  // new read-only property
   mainThread.send("data");     // correct
   thisTid.ownerTid.send("data2");  // also correct
}

mainThreadFoo()
{
    Tid workThread = spawn(&workThreadFoo);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list