Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using OSMemoryBarrier() with KVO



Hi,

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?

Thanks,
pt.
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.