www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Getting All Instances of a Thread-Local

reply dsimcha <dsimcha yahoo.com> writes:
Using D2's builtin thread-local storage, is there a way to get all instances
(one per thread) of a given thread-local variable?  If not, can anyone
recommend any workarounds, given that:

1.  Each instance of this variable is not written to after initialization,
i.e. not more than once during the execution of the program.
2.  I must be able to tell instances created by threads that are still alive
from those created by dead threads.  This rules out simply appending the
values to an array.
Jan 16 2009
parent reply Sergey Gromov <snake.scaly gmail.com> writes:
Sat, 17 Jan 2009 05:17:29 +0000 (UTC), dsimcha wrote:

 Using D2's builtin thread-local storage, is there a way to get all instances
 (one per thread) of a given thread-local variable?  If not, can anyone
 recommend any workarounds, given that:
 
 1.  Each instance of this variable is not written to after initialization,
 i.e. not more than once during the execution of the program.
 2.  I must be able to tell instances created by threads that are still alive
 from those created by dead threads.  This rules out simply appending the
 values to an array.
I wonder if struct destructor is called if you put it in TLS and thread dies. Then you could use RAII to remove irrelevant data from the 'simple array'.
Jan 17 2009
parent reply dsimcha <dsimcha yahoo.com> writes:
== Quote from Sergey Gromov (snake.scaly gmail.com)'s article
 Sat, 17 Jan 2009 05:17:29 +0000 (UTC), dsimcha wrote:
 Using D2's builtin thread-local storage, is there a way to get all instances
 (one per thread) of a given thread-local variable?  If not, can anyone
 recommend any workarounds, given that:

 1.  Each instance of this variable is not written to after initialization,
 i.e. not more than once during the execution of the program.
 2.  I must be able to tell instances created by threads that are still alive
 from those created by dead threads.  This rules out simply appending the
 values to an array.
I wonder if struct destructor is called if you put it in TLS and thread dies. Then you could use RAII to remove irrelevant data from the 'simple array'.
No, it isn't. Just tried it.
Jan 17 2009
parent Sergey Gromov <snake.scaly gmail.com> writes:
Sat, 17 Jan 2009 16:02:12 +0000 (UTC), dsimcha wrote:

 == Quote from Sergey Gromov (snake.scaly gmail.com)'s article
 Sat, 17 Jan 2009 05:17:29 +0000 (UTC), dsimcha wrote:
 Using D2's builtin thread-local storage, is there a way to get all instances
 (one per thread) of a given thread-local variable?  If not, can anyone
 recommend any workarounds, given that:

 1.  Each instance of this variable is not written to after initialization,
 i.e. not more than once during the execution of the program.
 2.  I must be able to tell instances created by threads that are still alive
 from those created by dead threads.  This rules out simply appending the
 values to an array.
I wonder if struct destructor is called if you put it in TLS and thread dies. Then you could use RAII to remove irrelevant data from the 'simple array'.
No, it isn't. Just tried it.
OTOH, if you can gain access to the data, it's not thread-local anymore. Simply put your data synchronously into a global array when it's ready, and synchronously remove it when a thread dies. You can use scope() or RAII in your thread function for that.
Jan 18 2009