Re: Thread Safety
Re: Thread Safety
- Subject: Re: Thread Safety
- From: Chris Hanson <email@hidden>
- Date: Wed, 20 Jun 2007 14:37:29 -0700
On Jun 20, 2007, at 8:37 AM, Yves Poissant wrote:
Some other functions don't have this topic. What is to be assumed in
those cases? Obviously, the safest bet is to assume that those
functions are not thread safe. But is that the correct assumption?
It's a necessary but not sufficient assumption. In the absence of
specific information to the contrary, you must assume that a function,
method, or data structure:
(1) Cannot itself be invoked from multiple threads at once. This is
the traditional definition of "thread-safe."
(2) Cannot be made thread-safe by locking or synchronizing around its
use. This is because you may not control all call sites, and cannot
force everything to use your locking or synchronization mechanism.
(3) As a consequence of #1 and #2, it cannot be used or invoked on any
thread other than the main thread.
I have seen a truly disturbing number of situations where people try
to "make" a facility "thread-safe" by surrounding its use with locks.
Since you can't control every call site, this is a recipe for disaster.
-- Chris
_______________________________________________
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