title: How prevent race condition inside UIButton touchDown and touchUpInside?
body: <p>I have a <code>UIButton</code> with two events. <code>touchUpInside</code> and <code>touchDown</code>. The button uses for voice recording so can be touched multiple times sequentially. When <code>touchDown</code> occured it does prepare and start recording and when <code>touchUpInside</code> occured it finishes recording.
  <code>touchDown</code> commands execute in another thread:</p>
  
  <pre><code>DispatchQueue.global(qos: .userInteractive).async {
  //prepare and start voice recording
  }
  </code></pre>
  
  <p><code>touchUpInside</code> commands executes in main thread.
  The problem is I have some variables that use in both events(race condition occured). For example before recorder instance inside <code>touchDown</code> event prepared, <code>touchUpInside</code> event occur.  So how control race condition? I know a little about DispatchGroup but I can't handle this situation with them. Thanks for help.</p>