This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [c++0x] std::thread fixes
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "libstdc++" <libstdc++ at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 22 Jan 2009 01:29:17 +0000
- Subject: Re: [c++0x] std::thread fixes
- References: <4348dea50901211542p24118c39tcd0f30c37d5297b2@mail.gmail.com>
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