On May 19, 2011, at 13:56, Sean McBride wrote:

>> Would it be correct to restate it
>> like this…
>> 
>> "In most cases, although you can allocate instances of these classes on
>> any thread, each instance must receive messages only from the thread
>> which allocated it."
> 
> I believe so.  

I don't believe so. The trouble is that "thread safety" isn't a clearly defined 
attribute, it's merely a discussion topic. There's more to thread safety than 
who can message when.

I believe the sentence is question is talking about atomicity, which is a 
low-level element of thread safety. "In most cases" the problem, at the level 
of the class itself, is simply that the class's methods are not atomic. "In 
most cases" you can use these classes from any thread as long as you invoke 
(enter and exit from) one method at a time.

In a *few* cases (of which NSManagedContext is believed to be one), objects of 
the class keep some thread-specific information such as which run loop to 
invoke completion routines on. In those cases, atomicity isn't enough -- it 
might be necessary to send messages only within the thread that created the 
object.

> See also:
> <http://www.mikeash.com/pyblog/friday-qa-2009-01-09.html>

While I don't think there's anything actually inaccurate in that blog post, I 
remember thinking when I first read it that Mike hadn't really disentangled the 
different strands of the problem. As a result, I think this post is useful only 
for sounding alarm bells, not for figuring out a way to silence them.


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to