[swift-users] Lazy expression is ambiguous?

Quinn "The Eskimo!" eskimo1 at apple.com
Mon Sep 12 05:02:59 CDT 2016


On 12 Sep 2016, at 09:20, Rick Mann <rmann at latencyzero.com> wrote:

> I've always wondered why that was the case.

Implementing `dispatch_once` so that it’s fast on all CPU architectures, including those with a weak memory model, requires that ‘once token’:

* be initialised to 0 before `dispatch_once` sees it

* not modified by anything other than `dispatch_once`

That’s true for [switching to Obj-C terminology here] global variables, which are initialised by the linker to 0 before any instruction in the process runs, but it’s not true for ivars.

If you want to see how this really works, you can check out the source in Darwin.

<http://opensource.apple.com/source/libdispatch/libdispatch-500.1.5/src/once.c>

Frankly, it hurts my brain )-:

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the swift-users mailing list