title: WIN32 Thread Program Issue
body: <p>This is my first time dealing with threads. </p>
  
  <p>When I run the program without the <code>GetCurrentThreadId()</code> function it executes without any issue. </p>
  
  <p>When I add that line of code it still executes but crashes once it reaches the end. Why is this?</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  
  static int tix[500];
  static int done = 0;
  HANDLE ghSemaphore;
  
  DWORD WINAPI ThreadFunction();
  
  int main(void)
  {
      DWORD threadID1, threadID2, threadID3, threadID4;
      HANDLE hThread1, hThread2, hThread3, hThread4;
  
      for (int i = 0; i &lt; 500; i++) //initialize array
      {
          tix[i] = 0;
      }
  
      ghSemaphore = CreateSemaphore(NULL, 1, 10, NULL);
  
      hThread1 = CreateThread(NULL, 0, ThreadFunction, NULL, 0, &amp;threadID1);
      hThread2 = CreateThread(NULL, 0, ThreadFunction, NULL, 0, &amp;threadID2);
      hThread3 = CreateThread(NULL, 0, ThreadFunction, NULL, 0, &amp;threadID3);
      hThread4 = CreateThread(NULL, 0, ThreadFunction, NULL, 0, &amp;threadID4);
  
      //printf("The thread ID: %d.\n", threadID1);
      //printf("The thread ID: %d.\n", threadID2);
      //printf("The thread ID: %d.\n", threadID3);
      //printf("The thread ID: %d.\n", threadID4);
  
      if (done = 1)
      {
          CloseHandle(hThread1);
          CloseHandle(hThread2);
          CloseHandle(hThread3);
          CloseHandle(hThread4);
      }
  
      for (int j = 0; j &lt; 500; j++)
      {
          if (tix[j] = 0)
          {
              printf("not sold");
          }
          else if (tix[j] = 1)
          {
              printf("sold");
          }
      }
  
      return 0;
  }
  
  DWORD WINAPI ThreadFunction()
  {
      WaitForSingleObject(ghSemaphore, 0);
  
      printf("current thread running : %d\n", GetCurrentThreadId());
  
      int i = 0;
      if (done != 0) // if loop to test wether or not the array is full
      {
          while (tix[i] = 1) //traverse the array to find a open spot
          {
              i++;
          }
          tix[i] = 1;
  
      }
      if (i == 499) //if i is 499, set test variable to 1
      {
          done = 1;
          return 0;
      }
  
      ReleaseSemaphore(ghSemaphore, 1, NULL);
  }
  </code></pre>