Is DispatchSemaphore a good replacement for NSLock? : <p>I've been using <code>NSLock</code>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 <code>DispatchSemaphore</code>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</p>

<pre><code>let lock = NSLock()
lock.lock()
// do things...
lock.unlock()
</code></pre>

<p>with</p>

<pre><code>let semaphore = DispatchSemaphore(value: 1)
semaphore.wait()
// do things...
semaphore.signal()
</code></pre>

<p>or will I run into issues regarding thread-safety anyway?</p>
