]> git.sesse.net Git - stockfish/commitdiff
Fix cond_signal() semantics when using OLD_LOCKS
authorMarco Costalba <mcostalba@gmail.com>
Sat, 31 Dec 2011 14:27:14 +0000 (15:27 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 31 Dec 2011 14:40:12 +0000 (15:40 +0100)
In Windows when OLD_LOCKS is defined we use SetEvent() to mimic
the semantic of the POSIX pthread_cond_signal().

Unfortunatly there is not a direct mapping because with SetEvent()
the state of an event object remains signaled until it is set
explicitly to the nonsignaled state or until a single waiting thread
has been released. Instead in case of pthread_cond_signal(), if there
are no waiting threads it has no effect. What we may want is something
like PulseEvent() instead of SetEvent(). Unfortunatly it is documented
by Mcrosoft as 'unreliable' due to spurious wakes up that could
filter out the signal resetting. So we opt to reset manually any
pending signaled state before to go to sleep.

This fixes the strange misbehaves during 'stockfish bench'
when using OLD_LOCKS under Windows.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/lock.h

index 3b3de1ac122718843e261597823a3f8661d31bc5..0af1443d740f47a81532da075916955e58d4bd64 100644 (file)
@@ -75,8 +75,8 @@ typedef HANDLE WaitCondition;
 #  define cond_init(x) { *x = CreateEvent(0, FALSE, FALSE, 0); }
 #  define cond_destroy(x) CloseHandle(*x)
 #  define cond_signal(x) SetEvent(*x)
-#  define cond_wait(x,y) { lock_release(y); WaitForSingleObject(*x, INFINITE); lock_grab(y); }
-#  define cond_timedwait(x,y,z) { lock_release(y); WaitForSingleObject(*x,z); lock_grab(y); }
+#  define cond_wait(x,y) { ResetEvent(*x); lock_release(y); WaitForSingleObject(*x, INFINITE); lock_grab(y); }
+#  define cond_timedwait(x,y,z) { ResetEvent(*x); lock_release(y); WaitForSingleObject(*x,z); lock_grab(y); }
 
 #endif