getTid wrapper

Timothee Cour thelastmammoth at gmail.com
Tue Mar 4 10:09:54 PST 2014


Thanks, that works
does it make sense to add a function to do that?
as it stands there are 2 separate ways,  cast(void*)Thread.getThis and
cast(void*)getTid, so having a function would make it the preferred way.



On Tue, Mar 4, 2014 at 9:42 AM, ollie <ollie at home.net> wrote:

> On Mon, 03 Mar 2014 20:39:17 -0800, Timothee Cour wrote:
>
> > I couldn't find a wrapper to get current thread id.
> > There is Thread.getThis but the address it returns is the same for all
> > threads as explained here (http://ddili.org/ders/d.en/concurrency.html)
> so
> > it's not useful for logging.
> >
>
> I ran into this problem with threads. You can't just take a pointer to a
> thread (ie &Thread.getThis). You have to use a cast(void*) for it to work.
> I put the following print statement where I created the thread and in the
> created thread:
>
>     writefln("Thread %X is%s the main thread.", cast(void*)Thread.getThis,
>               thread_isMainThread ? "" : "n't");
>
> This worked, otherwise using '&' to get the pointer gave the same address.
>
> ollie
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140304/6c6dc6f6/attachment.html>


More information about the Digitalmars-d-learn mailing list