wait for acknowledgements correctly

pthread_cond_wait() can have spurious wakeups, so we need to be sure
that the condition is actually true when we return from this function.
Thanks to Chris Brannon for the patch.
This commit is contained in:
William Hubbs 2009-06-25 17:05:51 -05:00
commit 3687f16b09

View file

@ -170,7 +170,8 @@ static void request_espeak_stop(void)
pthread_mutex_lock(&queue_guard);
runner_must_stop = 1;
pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */
pthread_cond_wait(&stop_acknowledged, &queue_guard);
while(runner_must_stop == 1)
pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */
pthread_mutex_unlock(&queue_guard);
}