[libdispatch-dev] dispatch_once_t must have global or static scope?
Daniel A. Steffen
dsteffen at apple.com
Thu Jul 26 10:30:23 PDT 2012
the main issue with dynamically allocated storage is safe initialization of the dispatch_once token value.
E.g. for an object with a dispatch_once_t instance variable, depending on how that object is made visible to other threads after creation, a memory barrier will be required on some platforms to ensure the zeroing of the dynamically allocated storage is visible to other CPUs before the object pointer.
On Jul 26, 2012, at 10:14, Michael Ash <michael.ash at gmail.com> wrote:
> The GCD reference on developer.apple.com says, regarding dispatch_once_t:
> "Variables of this type must have global or static scope. The result of using this type with automatic or dynamic allocation is undefined."
> However, I can't find any explanation of why that would be the case, either in the documentation or the libdispatch code. Does anyone have any insight to shed on this? It's occasionally useful to have a dispatch_once_t member variable in an Objective-C object, and it would be nice to know if that's actually OK or not. I have a hard time figuring out how GCD could possibly care about the storage scope of the variable, but it's possible that I'm overlooking something.
> libdispatch-dev mailing list
> libdispatch-dev at lists.macosforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the libdispatch-dev