[libdispatch-dev] dispatch_once_t must have global or static scope?
michael.ash at gmail.com
Thu Jul 26 10:39:39 PDT 2012
On Jul 26, 2012, at 1:30 PM, Daniel A. Steffen wrote:
> 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.
Excellent! That's exactly the sort of thing I was hoping I hadn't thought of before, in terms of understanding the limitation.
Do I understand it correctly, then, that it's safe as an Objective-C instance variable, as long as you take the standard necessary measures before letting a pointer to that ivar leak out to other threads (memory barriers or synchronization to ensure that other threads see fully initialized object contents)?
Would it be possible to have a brief discussion of this added to the documentation? This may be a bit beyond the level that the docs intend to cover, though....
In any case, thanks a lot for your quick reply.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the libdispatch-dev