This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: [patch] Make std::tr1::shared_ptr thread-safe.


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 â

Attachment: signature.asc
Description: OpenPGP digital signature


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