     @objc(replyToAction:response:error:)
     func replyToAction(actionId: NSInteger, response: NSDictionary, error: String) {
         // lookup the semaphore for this action
+        objc_sync_enter(self.eventSemaphores)
         if let sem = self.eventSemaphores[actionId] {
             // place response in cache and signal on this semaphore
             self.replyCache[actionId] = ["result": response, "error": error]

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

        // clear semaphore and reply cache
        self.replyCache[actionId] = nil
        self.eventSemaphores[actionId] = nil
        objc_sync_exit(self.eventSemaphores)
        
        return reply
    }
