   {
     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)
+      }
+
       let kr = semaphore_signal(semp)
       assert(kr == KERN_SUCCESS, __FUNCTION__)
       return kr == KERN_SUCCESS


import Darwin.Mach
import Dispatch.time

struct SemaphorePool
{

final public class ChannelSemaphore
{
  private var svalue: Int32
  private var semp = semaphore_t()

  private var currentState = ChannelSemaphoreState.Ready
  private var selected = 0
