This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]