         let timeout = dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER)
 
         // after signal the reply should be ready in the cache
+        objc_sync_enter(self.eventSemaphores)
         if timeout != 0 {
             print("action timeout \(actionId), \(functionName)")
             self.replyCache[actionId] = ["error": "timeout"]

        } else {
            print("disgarding action reply \(actionId)")
        }
    }
    
    @objc(registerAction:)

        
        // create a semaphore for this action
        let sem = dispatch_semaphore_create(0)
        objc_sync_enter(self.eventSemaphores)
        self.eventSemaphores[actionId] = sem
        objc_sync_exit(self.eventSemaphores)
        
        // dispatch event
        self.sendEventWithName("callAction", body: ["id": actionId, "action": functionName, "args": args])
