title: How to make thread synchronization without using mutex, semorphore, spinLock and futex?
body: <p>This is an interview question, the interview has been done. </p>
  
  <p>How to make thread synchronization without using mutex, semorphore, spinLock and futex ?</p>
  
  <p>Given 5 threads, how to make 4 of them wait for a signal from the left thread at the same point ? 
  it means that when all threads (1,2,3,4) execute at a point in their thread function, they stop and wait for 
  signal from thread 5 send a signal otherwise they will not proceed. </p>
  
  <p>My idea:</p>
  
  <p>Use global bool variable as a flag, if thread 5 does not set it true, all other threads wait at one point and also set their
  flag variable true. After the thread 5 find all threads' flag variables are true, it will set it flag var true. </p>
  
  <p>It is a busy-wait. </p>
  
  <p>Any better ideas ? </p>
  
  <p>Thanks</p>
  
  <pre><code> the pseudo code:
   bool globalflag = false; 
   bool a[10] = {false} ;  
   int main()
   {
    for (int i = 0 ; i &lt; 10; i++)
    pthread_create( threadfunc, i ) ; 
  
        while(1)
        {
           bool b = true; 
           for (int i = 0 ; i &lt; 10 ; i++)
           {  
                b = a[i] &amp; b ; 
           }
           if (b) break; 
      }
    }
    void threadfunc(i)
    {
     a[i] = true; 
     while(!globalflag); 
    }
  </code></pre>