Thread overview
[Issue 6224] New: Make a read-only public ownerTid property for std.concurrency
Jun 29, 2011
Andrej Mitrovic
Jun 29, 2011
Andrej Mitrovic
Jan 22, 2013
Andrej Mitrovic
Jan 22, 2013
Andrej Mitrovic
[Issue 6224] Add an ownerTid property in std.concurrency
Jan 22, 2013
Andrej Mitrovic
June 29, 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@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@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: -------
June 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6224



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-06-29 16:11:36 PDT ---
I forgot I can also use spawn to send the Tid, e.g.:

void workThreadFoo(Tid mainThread)
{
}

spawn(&workThreadFoo, thisTid);

It would still be nice to have a ownerTid property though, this is a feature request. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6224


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Windows                     |All


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-22 15:22:35 PST ---
Ok apparently there's a global but private 'owner' Tid. The problem is this is equal to Tid.init for the main thread since Tid is a struct. I don't think it's wise to simply return:

/**
 * Return the Tid of the thread which
 * spawned the caller's thread.
 */
@property Tid ownerTid()
{
    return owner;
}

As calling ownerTid.send() will segfault due to mbox being null. So what should
be done instead, maybe throw an exception in ownerTid() if mbox is null?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6224



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-22 15:24:33 PST ---
(In reply to comment #2)
> The problem is this is
> equal to Tid.init for the main thread since Tid is a struct.

That wasn't worded properly. It's .init because it doesn't have a parent, regardless of whether it's a struct or class.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6224


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody@puremagic.com        |andrej.mitrovich@gmail.com
            Summary|Make a read-only public     |Add an ownerTid property in
                   |ownerTid property for       |std.concurrency
                   |std.concurrency             |


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-22 15:59:50 PST ---
https://github.com/D-Programming-Language/phobos/pull/1092

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6224



--- Comment #5 from github-bugzilla@puremagic.com 2013-03-08 09:53:55 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/dd9b31ccaef70915c7a2b18b05d9f699fbb4ae5f Fixes Issue 6224 - Add ownerTid() property.

https://github.com/D-Programming-Language/phobos/commit/9cb2065fe6f2302a3c47f1aff3e005de5c90c110 Merge pull request #1092 from AndrejMitrovic/Fix6224

Issue 6224 - Add ownerTid() property.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6224


Alex Rønne Petersen <alex@lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex@lycus.org
         Resolution|                            |FIXED


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