• 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
property-level locking (was Re: Suppressing warning)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

property-level locking (was Re: Suppressing warning)


  • Subject: property-level locking (was Re: Suppressing warning)
  • From: Chris Hanson <email@hidden>
  • Date: Thu, 17 Apr 2008 14:36:13 -0700

On Apr 17, 2008, at 1:50 PM, Jeff LaMarche wrote:

When creating a synchronized accessor, like this (simple example):

- (NSString *)foo
{
@synchronized(foo)
{
return foo;
}
}

I'd question why you're writing a synchronized accessor in the first place.  Accessors are almost always the least correct place to introduce locking; you almost always want at least object-level granularity to your synchronization, if not object graph (or subgraph)-level locking.  The reason for this is that accessor-level locking does nothing to enforce multiple-property invariants for your classes.

Consider a Person that has givenName, familyName, and fullName properties; the fullName is synthesized by returning the givenName and familyName.  If one thread changes the givenName while another changes the familyName, and the properties are locked individually instead of against the whole object, then you can have a situation where fullName will return an inconsistent value.

This is why in Core Data, locking is implemented by having NSManagedObjectContext conform to NSLocking:  It locks at the level of an object graph, rather than at the level of a particular object or one specific property of an individual object.

  -- 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

  • Follow-Ups:
    • Re: property-level locking (was Re: Suppressing warning)
      • From: Jeff LaMarche <email@hidden>
References: 
 >Suppressing warning (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: Re: Forcing Xcode to prefer a specific dylib
  • Next by Date: Re: Hello
  • Previous by thread: Re: Suppressing warning
  • Next by thread: Re: property-level locking (was Re: Suppressing warning)
  • Index(es):
    • Date
    • Thread