title: Implementing condition variables for CRITICAL_SECTIONs for Winthreads for XP
body: <p>I have a desire for POSIX style condition variables on Win32. I have some code that needs to run on XP, so I can't use Vista/Server 2008's <code>CONDITION_VARIABLE</code>. </p>
  
  <p>It makes use a of a pseudo condition variable class currently, which is based on leaving the critical section and signaling an auto reset event for signaling / waking. For waiting on the condition variable, it leaves the critical section, <code>WaitForSingleObject</code>s on the event, and then reenters the critical section. This is mostly fine, but it doesn't support broadcast, and may have other issues with regard to fairness, which I don't care too much about. </p>
  
  <p>We do use boost, so I know know I could use boost threads or pthreads-win32, which support condition variables, but ideally I would like the interface to be such that I can drop in the Microsoft implementation when/if it becomes possible to use it directly. I have seen <a href="http://www.cse.wustl.edu/~schmidt/win32-cv-1.html" rel="noreferrer">Strategies for Implenting POSIX Condition Variables on Win32</a>, but the "best" (most correct) solution uses a Mutex and not a <code>CRITICAL_SECTION</code>. There is a sketch of an implementation with a <code>CRITICAL_SECTION</code> in the <a href="http://www.cse.wustl.edu/~schmidt/win32-cv-2.html" rel="noreferrer">second part</a>, but it is not complete, and the other solutions with <code>CRITICAL_SECTION</code>s concern me due to the concerns outlined for them in the article. </p>
  
  <p>In short, how do I implement a correct, not necessarily fair (but that would be nice), condition variable on win32 for critical sections such that I can drop in Microsoft's implementation when it becomes available to me?</p>