[patch] Make std::tr1::shared_ptr thread-safe.

Ulrich Drepper drepper@redhat.com
Wed Mar 30 18:25:00 GMT 2005


Paolo Carlini wrote:

> Then, readd to the library implementations of exchange_and_add for the
> platforms that can implement it, otherwise fall back to the stop-gap
> solution (some configury bits needed).

Using exchange_and_add is dangerous, it should not be used.

Granted, it will hurt only broken programs, but only those will use an
object with zero use anyway.

The problem is that is two thread simultaneously call lock, one suddenly
succeeds since one of the exchange_and_add comes first.  The result is
the first thread will throw an exception and destroy the object while
the second thinks all is fine and continues its work with a broken pointer.

The copmare_and_exchange I used is the correct solution.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050330/e87e8f04/attachment.sig>


More information about the Libstdc++ mailing list