title: Creating a thread that waits for input.
body: <p>I asked a question earlier today (<a href="https://stackoverflow.com/questions/32918479/loading-phasset-data-fast-xcode-ios?noredirect=1#comment53664703_32918479">find it here</a>) regarding sending
  large data to a server, and a person commented and said that a background task
  should handle the job.</p>
  
  <p>I am assuming that he/she means that a thread should handle the task.</p>
  
  <p><strong>So my question now is</strong>: How do I create a thread that waits for input?</p>
  
  <p>The process will look something like this:</p>
  
  <ol>
  <li>Main thread (MT) tells the worker thread (WT) to load an asset</li>
  <li>WT copies a chunk of data from the asset and assembles a network packet </li>
  <li>WT sends the network packet and waits </li>
  <li>WT waits for MT to tell it when to repeat step 2 through 4</li>
  </ol>
  
  <p>When data has been fully transmitted the thread is destroyed.</p>
  
  <p><strong>Note</strong>: I am not using HTTP, I am using TCP with my custom protocol on top of TCP.</p>
  
  <p><strong>Explanation:</strong>
  The reason I need to keep the thread waiting is because when I open a very large asset of 200MB or larger, it takes some time for the asset to be loaded.</p>
  
  <p>The larger the asset data, the longer time the app has to wait.</p>
  
  <p>If I want just a 2MB chunk of the asset, I have to load the asset, wait some time for it to be loaded, copy a chunk of 2MB, and then exit the completion block.</p>
  
  <p>Then I send the data, and wait for the server to send an ACK signal, and repeat the process.</p>
  
  <p>This will take some time and the network activity shows that there are several seconds of dead-time where the app isn't doing anything, and that's all because of time it takes for the asset to be loaded.</p>
  
  <p>The person in my previous question said that it's better to load the asset in a background task and NOT LEAVE the completion block of <code>requestImageForAsset</code> and simply keep the task running until the chunk has been sent, and then send the next chunk.</p>
  
  <p>I hope this clears any further confusions.</p>