title: Are there ways to use syncthreads in a conditional while loop in cuda?
body: <p>Let's assume that there exist 64 threads per thread block.</p>
  
  <p>Each thread runs following code:</p>
  
  <pre><code>int tid = threadIdx.x;
  
  while (tid &lt; 96) {
    // write data to shared memory
    __syncthreads();
    // read data from shared memory
    tid += 64;
  }
  </code></pre>
  
  <p>In this case, the second run of while statement causes last 32 threads not to reach <code>__syncthreads()</code>, and I think this will result in undefined behavior.</p>
  
  <p>Or, does __syncthreads() work correctly since last 32 threads reach the end of the code?</p>
  
  <p>I currently can't find out how to solve this kind of problems.</p>
  
  <p>Do I have to change algorithms?</p>