[cpp-threads] Asynchronous Execution Issues

Doug Lea dl at cs.oswego.edu
Sat Apr 25 15:47:39 BST 2009


Anthony Williams wrote:
> 
> No. It is up to the library when it destroys the threads. If you allow 
> your task to run on a reused thread then you have to accept that the 
> thread_locals may already exist because the thread has already been used 
> for one or more tasks, and that the thread_locals will persist until the 
> library decides to kill the thread, possibly after reusing the thread 
> many times, and possibly not.
> 

For what it is worth from analogous Java experience, most users
seem to be OK with this -- if you are using a pooled/cached
thread, you can't count on the state of thread-locals, so
should only use them for purposes that don't rely on
thread-local values for correctness, which is still a
lot of territory.  We periodically
get requests to provide some way to clear all thread-locals
on reuse but we can't comply in any reasonable way; among
other reasons because we don't want to interfere with frameworks
(including those for security) that set up a bunch of otherwise
inaccessible thread-locals that should be maintained for all
threads in a pool. So the best we can do is supply methods that
allow one-by-one removal of the thread-locals you know about.

(In Java we don't have to deal with destructors though, which
complicates choices here.)


-Doug



More information about the cpp-threads mailing list