On Tue, Mar 4, 2014 at 2:34 AM, Stanislav Blinov <stanislav.blinov@gmail.com> wrote:
On Tuesday, 4 March 2014 at 04:39:33 UTC, 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

That is not true.


as explained here (http://ddili.org/ders/d.en/concurrency.html)

Where exactly?

quoting from there:
"The type of thisTid is Tid, but its value has no significance for the program. Further, both threads report it to be surprisingly at the same address:
Owner : Tid(std.concurrency.MessageBox), address: 809C360
Worker: Tid(std.concurrency.MessageBox), address: 809C360"


Likewise with writeln(&Thread.getThis);

 
I couldn't find it, but if Ali's book states that Thread.getThis() returns the same reference, it's a bug in the book that should be fixed.


auto getTid() to class Thread

core.thread.Thread.getThis();
std.concurrency.thisTid;

The latter one is mentioned in that same chapter.

How would I print a number/string that uniquely identifies a thread?

Tid is an opaque type, writeln(thisTid) isn't of any use.

struct Tid
{
private:
    this( MessageBox m )
    {
        mbox = m;
    }


    MessageBox  mbox;
}