Re: Lockless thread-safe accessor using blocks: how to?
Re: Lockless thread-safe accessor using blocks: how to?
- Subject: Re: Lockless thread-safe accessor using blocks: how to?
- From: David Duncan <email@hidden>
- Date: Thu, 14 Apr 2011 10:09:08 -0700
On Apr 14, 2011, at 10:02 AM, WT wrote:
> I looked at dispatch_once() at one point, but I'm still confused by how it works.
dispatch_once uses a predicate (just a flag) to determine if it should run the block or not. If that flag is false, then it sets the flag to true and executes the block. If the flag is true, it does nothing. What makes dispatch_once useful over a simple if statement is that it ensures that if you execute dispatch_once concurrently from multiple threads that flag gets updated exactly once, and the block gets called exactly once.
--
David Duncan
_______________________________________________
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