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 CONDITION_VARIABLE
.
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, WaitForSingleObject
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.
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 Strategies for Implenting POSIX Condition Variables on Win32, but the "best" (most correct) solution uses a Mutex and not a CRITICAL_SECTION
. There is a sketch of an implementation with a CRITICAL_SECTION
in the second part, but it is not complete, and the other solutions with CRITICAL_SECTION
s concern me due to the concerns outlined for them in the article.
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?