• 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: Lockless thread-safe accessor using blocks: how to?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Lockless thread-safe accessor using blocks: how to?
      • From: WT <email@hidden>
References: 
 >Re: Lockless thread-safe accessor using blocks: how to? (From: Jonathan Taylor <email@hidden>)
 >Re: Lockless thread-safe accessor using blocks: how to? (From: WT <email@hidden>)
 >Re: Lockless thread-safe accessor using blocks: how to? (From: Jonathan Taylor <email@hidden>)
 >Re: Lockless thread-safe accessor using blocks: how to? (From: David Duncan <email@hidden>)
 >Re: Lockless thread-safe accessor using blocks: how to? (From: WT <email@hidden>)

  • Prev by Date: Re: Lockless thread-safe accessor using blocks: how to?
  • Next by Date: Re: Cocoa witch's broom
  • Previous by thread: Re: Lockless thread-safe accessor using blocks: how to?
  • Next by thread: Re: Lockless thread-safe accessor using blocks: how to?
  • Index(es):
    • Date
    • Thread