Re: thread safety of C++ standard library
Re: thread safety of C++ standard library
- Subject: Re: thread safety of C++ standard library
- From: Jens Alfke <email@hidden>
- Date: Tue, 1 Dec 2009 14:05:41 -0800
On Dec 1, 2009, at 1:36 PM, John Weeks wrote:
In particular, is std::sort thread-safe when working with distinct
containers? That is, std::sort(iterator, iterator, predicate) where
the
iterators point to different containers.
I don't know for sure, but I would guess not. It's often (generally?)
considered inappropriate to design thread-safety into low-level
collection classes, as it adds overhead to the more common case where
an object is being used from only one thread.
For instance, the original Java 1.0 collection classes were thread-
safe, but were soon deprecated in favor of the Java 1.2 collections
that are not, and performance was one reason for the change.
CoreFoundation's collections aren't thread-safe either.
It's better to look at the concurrency of your larger scale object
model and add locks at appropriate places, than to assume things get
handled for you at a lower level. (In particular, in the case you
describe that works on two collections, I can imagine it would be very
hard for STL to avoid lock ordering problems; you'd need to decide on
a policy yourself.)
—Jens _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden