Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple condition-variable for Win32

14 views
Skip to first unread message

Bonita Montero

unread,
May 18, 2016, 4:49:37 PM5/18/16
to
I just wrote a simple conditon-variable for Win32.
Windows has condition-variables since Windows Vista
and Windows Server 2008, but if you want to have
such functionality before, my condvar would be
appropriate.

I just meged all headers and the implementation in
one file: http://pastebin.com/E9CF0kTu

--
http://facebook.com/bonita.montero/

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

Bonita Montero

unread,
May 19, 2016, 12:28:08 PM5/19/16
to
Am 18.05.2016 um 22:49 schrieb Bonita Montero:

I just simplified the code a bit.
Now I use InterlockedIncrement/Decrement instead of
InterlockedCompareExchange: http://pastebin.com/Ew3EcmQ3

Bonita Montero

unread,
May 21, 2016, 4:04:51 PM5/21/16
to
There was a conceptual flaw in my code which led to a race-condition.
And there was another bug, which, if I fixed it with the former con-
cept, would heave led to a similar race-condition.
So I had to rewrite my condvar completely.
Here it is: http://pastebin.com/fdjHx9ec
Now the code is including a unit-test.

Theres something important with my code:
First Release() and ReleaseAll() can be called only while holding
the condvar; that's different from the posix-condvars, which can
be signalled without holding the mutex. When NDEBUG isn't defined,
my code always assert()s whether the thread calling Release() or
ReleaseAll() is holding the condvar.
Second, making Wait() having a timeout would make the simple approach
I took impossible. I'm pretty sure my approach is more efficient than
any implementation of posix-conforming condvars. If you would like
to have a timeout, you would have a timed Release() from another
thread.

--
http://facebook.com/bonita.montero/
0 new messages