• 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: @synchronized in thread safe accessors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @synchronized in thread safe accessors


  • Subject: Re: @synchronized in thread safe accessors
  • From: mmalc Crawford <email@hidden>
  • Date: Fri, 6 Feb 2009 21:48:45 -0800


On Feb 6, 2009, at 6:23 PM, Michael Ash wrote:

It's one less ivar to worry about. I retro-fitted the lock to one other
object I wanted to make thread-safe, only because I couldn't think of a way
of doing this safely with @synchronized(), and thought I'd ask before
committing. And now I'm wondering how @synthesize does atomic sets
internally...
I'm pretty sure it just does @synchronized(self) or the equivalent.

Actually, no it doesn't -- @synchronized is a comparatively heavyweight operation, and @synchronized(self) would represent an object-level lock. The implementation of synthesized atomic accessors is deliberately not documented since it may be subject to change, however locking is performed in a lighter-weight fashion and on a per- property basis.

Nevertheless:
One last thing: creating thread-safe getters and setters is almost
never the right thing to do. It's never sufficient and rarely required
to achieve overall thread safety. There are cases where it's useful
but they're rare. It's much better, in most cases, to concentrate on
synchronizing larger pieces of your object graph instead.

this is absolutely true (<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_6.html >).

mmalc

_______________________________________________

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


References: 
 >@synchronized in thread safe accessors (From: Nick Zitzmann <email@hidden>)
 >Re: @synchronized in thread safe accessors (From: Kyle Sluder <email@hidden>)
 >Re: @synchronized in thread safe accessors (From: Nick Zitzmann <email@hidden>)
 >Re: @synchronized in thread safe accessors (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: Read lines from very large text file
  • Next by Date: Re: NSTableView Popup Column issue
  • Previous by thread: Re: @synchronized in thread safe accessors
  • Next by thread: -[NSPersistentDocument isDocumentEdited] lazy until next click
  • Index(es):
    • Date
    • Thread