[cpp-threads] Asynchronous Execution Issues

Peter Dimov pdimov at mmltd.net
Sat Apr 25 01:16:24 BST 2009


Lawrence Crowl:
...
> First, consider the case of the caching_async.  Because the threads
> may persist, we need a handle on the list of threads so that we
> can inform a thread to die so that we destroy any thread-local
> variables before the global variables that they reference.

It is (today) a very bad idea to reference a global with a destructor from a 
thread_local because globals are destroyed first when exit() is called. I 
know that in C++0x it has been decided that thread locals should die first, 
but as nobody has yet written any code under this new model, it is not 
possible to draw any conclusions based on experience.

> Second, consider the case of the creating_async.  The problem here
> is a touch more subtle.  In particular, once the working thread has
> set its promise, it can start destroying thread-local variables.
> Unfortunately, we have no idea when that has or might happen.

Why is this a problem? 




More information about the cpp-threads mailing list