On May 31, 2012, at 3:28 PM, Lane Roathe wrote:

> Suggestions:
> 
> 1. remove the k prefix, by convention that is reserved for constants
> 
> 2. don't use the same var name for a local variable as for a global variable
> 
> 3. That should be something like:
> 
> static VLFContext* myVLFContext = nil;
> ...
>       if( !myVLFContext )
>               myVLFContext = [VLFContext alloc] init];
> ...
>       @synchronized( myVLFContext ) {
>       ...
>       }

You’ve got a potential race condition in the initializer. Using dispatch_once 
instead will solve that:

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
        myVLFContext = [[VLFContext alloc] init];
});

@synchronized(myVLFContext) {
        ...
}

If you keep having trouble with @synchronized, though, I’d recommend just 
switching to a pthread_mutex_t, a spin lock, or dispatch_sync. Any of these 
should have better performance than @synchronized anyway.

Charles
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to