Browse Source

Fix a tricky thread synchronization bug.

If a command ran to completion before the thread calling
fifo_add_command woke up, that thread would wait forever
for the command to start, never realizing that it had already
finished.
master
Christopher Brannon 8 years ago
parent
commit
1d8cec684b
1 changed files with 2 additions and 2 deletions
  1. 2
    2
      src/libespeak-ng/fifo.c

+ 2
- 2
src/libespeak-ng/fifo.c View File

my_start_is_required = 1; my_start_is_required = 1;
pthread_cond_signal(&my_cond_start_is_required); pthread_cond_signal(&my_cond_start_is_required);


while (!my_command_is_running) {
while (my_start_is_required && !my_command_is_running) {
if((status = pthread_cond_wait(&my_cond_command_is_running, &my_mutex)) != ENS_OK && errno != EINTR) { if((status = pthread_cond_wait(&my_cond_command_is_running, &my_mutex)) != ENS_OK && errno != EINTR) {
pthread_mutex_unlock(&my_mutex); pthread_mutex_unlock(&my_mutex);
return status; return status;
my_start_is_required = 1; my_start_is_required = 1;
pthread_cond_signal(&my_cond_start_is_required); pthread_cond_signal(&my_cond_start_is_required);
while (!my_command_is_running) {
while (my_start_is_required && !my_command_is_running) {
if((status = pthread_cond_wait(&my_cond_command_is_running, &my_mutex)) != ENS_OK && errno != EINTR) { if((status = pthread_cond_wait(&my_cond_command_is_running, &my_mutex)) != ENS_OK && errno != EINTR) {
pthread_mutex_unlock(&my_mutex); pthread_mutex_unlock(&my_mutex);
return status; return status;

Loading…
Cancel
Save