title: how to access list elements in each thread sequentially
body: <p>Recently I was asked this question in an phone interview </p>
  
  <p>"Say there are 3 array lists l1, l2 &amp; l3 of same length. 
   Three threads accessing three lists. 
   Say T1 -> l1, T2 ->l2 &amp; T3 ->l3. 
   It should print in the order say first element of 1st then first element of 2nd       list and then first element of 3rd list. 
  Then second element of 1st then second element of 2nd list and then second element of 3rd list."</p>
  
  <p>I replied that using semaphore can solve this problem but when I tried myself with semaphore could not get the proper answer.
  What is wrong in my below code</p>
  
  <pre><code>namespace Semaphore_Example
  {
      class Program
      {
          static List&lt;int&gt; list1 = new List&lt;int&gt;{ 1, 2, 3, 4, 5 };
          static List&lt;int&gt; list2 = new List&lt;int&gt; { 1, 2, 3, 4, 5 };
          static List&lt;int&gt; list3 = new List&lt;int&gt; { 1, 2, 3, 4, 5 };
  
          static Semaphore semaphore = new Semaphore(0,3);
          static SemaphoreSlim _sem = new SemaphoreSlim(3);    
  
          static void Main(string[] args)
          {
  
              Thread t1 = new Thread(show);
              Thread t2 = new Thread(show);
              Thread t3 = new Thread(show);
  
              t1.Start();
              t2.Start();
              t3.Start();
  
              Console.ReadLine();
          }
  
          static void show()
          {
              _sem.Wait();
  
              for (int i = 0; i &lt; 5; i++)
              {
                  Console.WriteLine(list1[i]);
                  Console.WriteLine(list2[i]);
                  Console.WriteLine(list3[i]);
              }
  
              _sem.Release();
  
          }
      }
  }
  </code></pre>