title: Thread-safe GetTickCount64 implementation for Windows XP
body: <p>I'm targeting Windows XP, and I need a function similar to GetTickCount64, that does not overflow.</p>
  
  <p>I couldn't find a decent solution that is correct and thread safe, so I tried to roll my own.</p>
  
  <p>Here's what I came up with:</p>
  
  <pre><code>ULONGLONG MyGetTickCount64(void)
  {
      static volatile DWORD dwHigh = 0;
      static volatile DWORD dwLastLow = 0;
      DWORD dwTickCount;
  
      dwTickCount = GetTickCount();
      if(dwTickCount &lt; (DWORD)InterlockedExchange(&amp;dwLastLow, dwTickCount))
      {
          InterlockedIncrement(&amp;dwHigh);
      }
  
      return (ULONGLONG)dwTickCount | (ULONGLONG)dwHigh &lt;&lt; 32;
  }
  </code></pre>
  
  <p>Is it really thread safe?</p>
  
  <p>Thread safety is difficult to check for correctness, so I'm not sure whether it's really correct in all cases.</p>