• 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: Using OSMemoryBarrier() with KVO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using OSMemoryBarrier() with KVO


  • Subject: Re: Using OSMemoryBarrier() with KVO
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 22 Apr 2008 21:41:27 -0500

On Apr 22, 2008, at 6:37 AM, Paul Thomas wrote:
I'm trying to implement a basic promise variable and I'm not sure if OSMemoryBarrier() is enough to make it correct. If anyone is familiar with the memory model, I'd appreciate a quick look-over.

It's basically like this:

{
   BOOL done;
   id result;
   NSError* error;
   NSException* exception;
}

Users ask for KVO notifications on 'done' and don't attempt to access any other ivars until done == YES. Then whatever thread or NSOperation or whatever that is responsible for delivering the result calls:

-(void)completeWithResult:(id)res
{
   result = res;
   [self willChangeValueForKey:@"done"];
   done = YES;
   OSMemoryBarrier();
   [self didChangeValueForKey:@"done"];
}

Is this enough? Or will I need to use a full blown lock?

What is it that you fear going wrong, such that you think even OSMemoryBarrier is necessary?


KVO notifications are delivered on the thread where will/ didChangeValueForKey: are called. There's no multi-threading issue inherent in the above code, even without OSMemoryBarrier.

-Ken
_______________________________________________

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: Using OSMemoryBarrier() with KVO
      • From: Paul Thomas <email@hidden>
References: 
 >Using OSMemoryBarrier() with KVO (From: Paul Thomas <email@hidden>)

  • Prev by Date: Re: NSString memory management question
  • Next by Date: "Safe" frameworks for privileged tools?
  • Previous by thread: Re: Using OSMemoryBarrier() with KVO
  • Next by thread: Re: Using OSMemoryBarrier() with KVO
  • Index(es):
    • Date
    • Thread