I used NSLockto synchronize the touch parts of the code, but I had problems due to the fact that they had to be unlocked from the same thread from which they were blocked. Then I discovered that the GCD DispatchSemaphoreseems to do the same, with the added convenience that they can be signaled from any stream. I was wondering, however, if this convenience comes at the cost of thread safety. Is it possible to replace
let lock = NSLock()
lock.lock()
lock.unlock()
with
let semaphore = DispatchSemaphore(value: 1)
semaphore.wait()
semaphore.signal()
or will i be facing thread safety issues anyway?
source
share