From 15091d82be7b4a0467090faf5f13d8bfdbff052b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 16 Mar 2022 00:22:58 +0100 Subject: [PATCH] fifo: Protect setting my_terminate_is_required We need to keep the mutex around setting it, to make sure that the visibility of setting it to true doesn't get delayed, notably not after the signal (which could entail that the signal becomes useless, leading to a hang). --- src/libespeak-ng/fifo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libespeak-ng/fifo.c b/src/libespeak-ng/fifo.c index dc60cc42..3f98f2a0 100644 --- a/src/libespeak-ng/fifo.c +++ b/src/libespeak-ng/fifo.c @@ -438,7 +438,9 @@ static void init(int process_parameters) void fifo_terminate() { + pthread_mutex_lock(&my_mutex); my_terminate_is_required = true; + pthread_mutex_unlock(&my_mutex); pthread_cond_signal(&my_cond_start_is_required); pthread_join(my_thread, NULL); my_terminate_is_required = false;