[c++0x] std::thread fixes

Jonathan Wakely jwakely.gcc@gmail.com
Thu Jan 22 01:29:00 GMT 2009


2009/1/21 Jonathan Wakely:
>
> Taking concurrent copies of the shared_ptr /is/ safe, and ensures the
> thread data is still valid even if_M_thread_data has been reset

I should point out that copying the shared_ptr isn't valid if it
happens at the same time as a reset or swap on the same object, so
unsafe of std::thread could still result in undefined behaviour.
Using copies of the shared_ptr might reduce the incidence of crashes,
but it would not make it properly safe or turn undefined behaviour
into well-defined.  That's why I chose not to go with the change.

Leaving the mutex in std::thread (and using it everywhere the
shared_ptr is accessed) would prevent more crashes, but at a greater
performance cost to all users.  It would simply mean that undefined
behaviour is likely to result in deadlock rather than a crash.

Jonathan



More information about the Libstdc++ mailing list