[c++0x] std::thread fixes
Thu Jan 22 02:31: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.
More information about the Gcc-patches