   {
     if OSAtomicIncrement32Barrier(&svalue) <= 0
     {
+      while semp == 0
+      { // if svalue was previously less than zero, there must be a wait() call
+        // currently in the process of initializing semp.
+        NSThread.sleepForTimeInterval(1e-10)
+        OSMemoryBarrier()
+      }
+
       let kr = semaphore_signal(semp)
       assert(kr == KERN_SUCCESS, __FUNCTION__)
       return kr == KERN_SUCCESS

    {
      return true
    }

    var kr: kern_return_t
    switch timeout


import Darwin.Mach
import Dispatch.time
import Foundation.NSThread

struct SemaphorePool
{
