title: array synchronization and multithreading
body: <p>I have a multithreaded application where I'm doing the following:</p>
  
  <p>Thread1: Reads data from a camera and stores it in ArrayFire array (CUDA backend).</p>
  
  <p>Thread2: Use ArrayFire to calculate certain results from the camera's data.</p>
  
  <p>Thread3: Send the results over the network. Calls host function on the array.</p>
  
  <p>The problem that I have is that when I do the last part of sending results over the network I need to copy the data from GPU to CPU using the host function. This causes jitter (varying delay).</p>
  
  <p>When looking at the source code of ArrayFire I notice that host uses CUDA stream synchronization method which (if I understood correctly) forces the only CUDA stream where all the threads are running to finish all the tasks that its doing.</p>
  
  <p>This causes the Thread3 to wait for the Thread2 to finish its ArrayFire calculation (if any occuring at that time) and it causes random jitter in Thread3 where I need to call host in order to copy the array to CPU memory.</p>
  
  <p>Are my assumptions correct, and if so, any suggestions on what to do?</p>