title: Safe to signal semaphore before deinitialization just in case?
body: <pre><code>class SomeViewController: UIViewController {
      let semaphore = DispatchSemaphore(value: 1)
  
      deinit {
          semaphore.signal() // just in case?
      }
  
      func someLongAsyncTask() {
          semaphore.wait()
          ...
          semaphore.signal() // called much later
      }
  }
  </code></pre>
  <p>If I tell a semaphore to wait and then deinitialize the view controller that owns it before the semaphore was ever told to signal, the app crashes with an <code>Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)</code> error. However, if I simply call <code>semaphore.signal()</code> in the <code>deinit</code> method of the view controller, disaster averted. However, if the async function returns before <code>deinit</code> is called and the view controller is deinitialized, then <code>signal()</code> is called twice, which doesn't seem problematic. But is it safe and/or wise to do this?</p>