• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Use them from only one thread at a time"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Use them from only one thread at a time"


  • Subject: Re: "Use them from only one thread at a time"
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 19 May 2011 14:31:23 -0700

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@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: "Use them from only one thread at a time"
      • From: Sean McBride <email@hidden>
References: 
 >"Use them from only one thread at a time" (From: Jerry Krinock <email@hidden>)
 >Re: "Use them from only one thread at a time" (From: Sean McBride <email@hidden>)

  • Prev by Date: Re: "Use them from only one thread at a time"
  • Next by Date: Re: The simplest way to fade out a view
  • Previous by thread: Re: "Use them from only one thread at a time"
  • Next by thread: Re: "Use them from only one thread at a time"
  • Index(es):
    • Date
    • Thread