Bug 6989 – Implement toString for std.concurrency.Tid
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-22T13:11:00Z
Last change time
2015-02-18T03:40:14Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2011-11-22T13:11:43Z
Currently calling write() on a Tid prints:
Tid(std.concurrency.MessageBox)
In earlier versions this used to be:
Tid
In either case, this isn't much information. I think it would be useful if toString was overloaded and returned a string with some sort of unique thread ID, e.g.:
writeln(spawn(&test)); // Tid(0x0001)
This could make it easier to debug some types of threading problems without having to use a debugger.
Comment #1 by andrej.mitrovich — 2013-01-25T11:42:52Z
Hmm it looks like there isn't such a thing as a cross-platform thread-identifier (at least not in Druntime).
Personally I like the idea of having named threads, where the name would be stored in a Tid. So you could do things like:
spawn("workThread", &func, args);
where the first pointer argument is the function. It might help with debugging, e.g. inspecting a Tid of a LinkTerminated exception could tell you which named thread threw the exception.
Comment #2 by andrej.mitrovich — 2013-03-25T11:34:26Z
(In reply to comment #1)
> Hmm it looks like there isn't such a thing as a cross-platform
> thread-identifier (at least not in Druntime).
Nevermind, there's actually m_addr, which is a uint on Windows and pthread_t on Posix (a pointer to _opaque_pthread_t).
So I think core.thread.Thread should expose a getThreadID() function which returns m_addr, and then Tid can expose this function internally and also use it for toString().
Comment #3 by andrej.mitrovich — 2013-09-17T13:30:06Z
Comment #4 by kevin.lamonte — 2014-09-02T01:32:39Z
*** Issue 13376 has been marked as a duplicate of this issue. ***
Comment #5 by sean — 2014-10-05T17:01:44Z
I think it's reasonable to add a Tid.id property that provides a unique name for a thread. I'd like to allow thread ids to be reused though. Then we could just use the MessageBox address. Providing a provably unique identifier to each thread across the entire run of the program would be expensive.
Comment #6 by andrej.mitrovich — 2014-10-05T18:55:59Z
(In reply to Sean Kelly from comment #5)
> Providing a provably unique
> identifier to each thread across the entire run of the program would be
> expensive.
Isn't starting a thread expensive enough that incrementing a simple counter should be good enough to generate an ID?
Comment #7 by github-bugzilla — 2014-12-02T09:51:54Z