1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Revert cond_signal() fix

It seems it yields to missing wake-up events with the
result of SF loosing on time as reported by many people.

So revert the patch and use a more robust approach: assume
there can be spurious wake ups events and make the code to
work also in those cases.

While debugging I found that WaitForSingleObject() had wrong
parameter 0 instead of INFINITE yielding to a crash while
exiting under Windows, strangely unnoticed til now.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-01-02 14:37:44 +01:00
parent 67338e6f32
commit cb1709ef5e
2 changed files with 5 additions and 4 deletions

View file

@ -75,8 +75,8 @@ typedef HANDLE WaitCondition;
# define cond_init(x) { *x = CreateEvent(0, FALSE, FALSE, 0); } # define cond_init(x) { *x = CreateEvent(0, FALSE, FALSE, 0); }
# define cond_destroy(x) CloseHandle(*x) # define cond_destroy(x) CloseHandle(*x)
# define cond_signal(x) SetEvent(*x) # define cond_signal(x) SetEvent(*x)
# define cond_wait(x,y) { ResetEvent(*x); lock_release(y); WaitForSingleObject(*x, INFINITE); lock_grab(y); } # define cond_wait(x,y) { 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); } # define cond_timedwait(x,y,z) { lock_release(y); WaitForSingleObject(*x,z); lock_grab(y); }
#endif #endif

View file

@ -202,7 +202,7 @@ void ThreadsManager::exit() {
// Wait for thread termination // Wait for thread termination
#if defined(_MSC_VER) #if defined(_MSC_VER)
WaitForSingleObject(threads[i].handle, 0); WaitForSingleObject(threads[i].handle, INFINITE);
CloseHandle(threads[i].handle); CloseHandle(threads[i].handle);
#else #else
pthread_join(threads[i].handle, NULL); pthread_join(threads[i].handle, NULL);
@ -452,6 +452,7 @@ void ThreadsManager::start_thinking(const Position& pos, const LimitsType& limit
cond_signal(&main.sleepCond); // Wake up main thread and start searching cond_signal(&main.sleepCond); // Wake up main thread and start searching
if (!asyncMode) if (!asyncMode)
while (!main.do_sleep)
cond_wait(&sleepCond, &main.sleepLock); cond_wait(&sleepCond, &main.sleepLock);
lock_release(&main.sleepLock); lock_release(&main.sleepLock);