March 04, 2014 Re: getTid wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to ollie Attachments:
| 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@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
>
|
Copyright © 1999-2021 by the D Language Foundation