Is DispatchSemaphore a good replacement for NSLock?
问题 I've been using NSLock s to synchronize touchy parts of code, but have been running into issues due to the fact that they must be unlocked from the same thread that they were locked from. Then I found that GCD's DispatchSemaphore s seem to do the same thing, with the added convenience that they can be signaled from any thread. I was wondering, though, if this convenience comes at the price of thread-safety. Is it advisable to replace let lock = NSLock() lock.lock() // do things... lock.unlock