digitalmars.D.learn - Thread.getThis()
- pmoore (23/23) Oct 14 2005 Hi,
- BCS (14/37) Oct 14 2005 try:
- JT (2/32) Oct 14 2005
- Niko Korhonen (8/9) Oct 15 2005 Exactly. Each call of the Thread.getThis() function returns a new
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
Oct 14 2005
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
Oct 14 2005
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
Oct 14 2005
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
Oct 15 2005