title: Multiple NSThreads synchronization
body: <p>I want to achieve the following task using <code>NSThread</code></p>
  
  <p>I've a main thread and three (3) workerThread T1, T2, T3. All these started at the same time from main thread, Main thread has an <code>int size</code> variable. Now I want to synchronize all three threads in a way they, when my each of the above threads will execute, it will print the following:</p>
  
  <p>//in main thread</p>
  
  <pre><code>- (void) mainFunction{
      size = 0;
  
      NSThread* T1 = [[NSThread alloc] initWithTarget:self
                                             selector:@selector(workerThread:)
                                               object:@"T1"];
      [T1 start];
  
  
      NSThread* T2 = [[NSThread alloc] initWithTarget:self
                                             selector:@selector(workerThread:)
                                               object:@"T2"];
      [T2 start];
  
      NSThread* T3 = [[NSThread alloc] initWithTarget:self
                                             selector:@selector(workerThread:)
                                               object:@"T3"];
      [T3 start];
  
  
  }
  </code></pre>
  
  <p>// worker thread</p>
  
  <pre><code>- (void) workerThread:(id)obj{
  
      size++;
      NSLog(@"Thread:%@--------Size:%d,obj,size)
  
  }
  </code></pre>
  
  <p>I want following output:</p>
  
  <pre><code>Thread:T1-------Size:1
  Thread:T2-------Size:2
  Thread:T3-------Size:3
  
  Thread:T1-------Size:4
  Thread:T2-------Size:5
  Thread:T3-------Size:6
  
  Thread:T1-------Size:7
  Thread:T2-------Size:8
  Thread:T3-------Size:9
  </code></pre>
  
  <p>and return the control back to main thread when <code>size=10</code></p>