         self.value = value
         signals = Array()
         lock = NSLock()
+        signaled = try! ThreadLocal()
     }
     
     //TODO: optimise with atomics for value. Will allow to run non-blocked sema faster


private enum Wakeable {
    case Loop(loop:RunnableRunLoopType)
    case Sema(sema:SemaphoreType)
}

private extension Wakeable {

        
        if value < 0 {
            lock.unlock()
            //defer {
            //    lock.lock()
            //}
            while !signaled && !timedout {
                timedout = wakeable.waitWithConditionalDate(until)
                signaled = self.signaled.value ?? false
            }
            self.signaled.value = false
            lock.lock()
        }
        
        return signaled
