On 10-04-29 07:40 PM, Sean Kelly wrote:
fawc...@uwindsor.ca Wrote:
Hi folks,
I'm crossposting this question from digitalmars.D.learn. Looking at
D2's documentation on the std.thread module,
http://www.digitalmars.com/d/2.0/phobos/std_thread.html
...there are several functions take a ThreadAddr value as an argument.
But there are no documented functions, methods or properties one can use
to obtain a ThreadAddr value.
I assume this is a documentation error. How do you get a ThreadAddr?
I've always tried to keep the thread module completely platform
agnostic so I'm not sure if these routines really should be public
at all, but that aside, a ThreadAddr is a platform-dependent type.
It's a pthread_t on Posix and a uint on Windows.
Thanks! If they do remain public, I'd vote to add a formal
currentThread() function, and a 'ThreadAddr getID()' accessor to the
library.
You'd get the address using pthread_self() on Posix and whatever the
equivalent is on Windows.
I believe it's GetCurrentThreadId() on Windows.
As a side-question: it considered bad form for a D library to have
platform-specific functionality? E.g., if for some reason Windows
didn't have any function for getting the current thread-id, is there a
convention that the D library shouldn't offer a "currentID()" function
at all, for portability reasons?
(My personal bias would be to offer it on whatever platforms supported
the feature, and document its absence elsewhere; or offer a
dummy-version on non-supporting platforms that caused a compilation
error when user code attempted to call it.)
Cheers,
Graham