Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 14, 2005 Thread.getThis() | ||||
---|---|---|---|---|
| ||||
Hi, I am calling the Thread.getThis() method to return the current thread then printing out the ptr. I am expecting the result to be the same each time I call the method but it isn't. Am I doing something really dumb? (It is nearly midnight :) import std.thread; import std.stdio; int main() { Thread t1 = Thread.getThis(); Thread t2 = Thread.getThis(); Thread t3 = Thread.getThis(); Thread t4 = Thread.getThis(); writefln("thread ptr = %d",cast(uint)&t1); writefln("thread ptr = %d",cast(uint)&t2); writefln("thread ptr = %d",cast(uint)&t3); writefln("thread ptr = %d",cast(uint)&t4); return 0; } I am getting the following output: thread ptr = 1244968 thread ptr = 1244972 thread ptr = 1244976 thread ptr = 1244980 |
October 14, 2005 Re: Thread.getThis() | ||||
---|---|---|---|---|
| ||||
Posted in reply to pmoore | try: int main() { Thread t1 = Thread.getThis(); Thread t2 = Thread.getThis(); Thread t3 = Thread.getThis(); Thread t4 = Thread.getThis(); writefln("thread ptr = %d",cast(uint)t1); writefln("thread ptr = %d",cast(uint)t2); writefln("thread ptr = %d",cast(uint)t3); writefln("thread ptr = %d",cast(uint)t4); return 0; } w/o '&' (IIRC t1 is already a pointer) In article <dipd6r$qtr$1@digitaldaemon.com>, pmoore says... > >Hi, > >I am calling the Thread.getThis() method to return the current thread then printing out the ptr. I am expecting the result to be the same each time I call the method but it isn't. Am I doing something really dumb? (It is nearly midnight :) > >import std.thread; >import std.stdio; > >int main() { >Thread t1 = Thread.getThis(); >Thread t2 = Thread.getThis(); >Thread t3 = Thread.getThis(); >Thread t4 = Thread.getThis(); >writefln("thread ptr = %d",cast(uint)&t1); >writefln("thread ptr = %d",cast(uint)&t2); >writefln("thread ptr = %d",cast(uint)&t3); >writefln("thread ptr = %d",cast(uint)&t4); >return 0; >} > >I am getting the following output: > >thread ptr = 1244968 >thread ptr = 1244972 >thread ptr = 1244976 >thread ptr = 1244980 > > |
October 14, 2005 Re: Thread.getThis() | ||||
---|---|---|---|---|
| ||||
Posted in reply to pmoore | I think you are getting the address of the references.
pmoore wrote:
> Hi,
>
> I am calling the Thread.getThis() method to return the current thread then
> printing out the ptr. I am expecting the result to be the same each time I call
> the method but it isn't. Am I doing something really dumb? (It is nearly
> midnight :)
>
> import std.thread;
> import std.stdio;
>
> int main() {
> Thread t1 = Thread.getThis();
> Thread t2 = Thread.getThis();
> Thread t3 = Thread.getThis();
> Thread t4 = Thread.getThis();
> writefln("thread ptr = %d",cast(uint)&t1);
> writefln("thread ptr = %d",cast(uint)&t2);
> writefln("thread ptr = %d",cast(uint)&t3);
> writefln("thread ptr = %d",cast(uint)&t4);
> return 0;
> }
>
> I am getting the following output:
>
> thread ptr = 1244968
> thread ptr = 1244972
> thread ptr = 1244976
> thread ptr = 1244980
>
>
|
October 15, 2005 Re: Thread.getThis() | ||||
---|---|---|---|---|
| ||||
Posted in reply to JT | JT wrote:
> I think you are getting the address of the references.
Exactly. Each call of the Thread.getThis() function returns a new instance of class Thread, which only /represents/ a thread and is not a naked pointer to a real thread or anything. So you have several instances of class Thread which all represent the same actual thread. Therefore the addresses of the references are different.
Niko Korhonen
SW Developer
|
Copyright © 1999-2021 by the D Language Foundation