From 9e03f403127bec584d2bc61d0ed519eacd80ad12 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Fri, 29 Dec 2023 14:43:59 +0900 Subject: [PATCH] Fix race condition when player thread is terminated Change-Id: I1db88e6f4f308e59eb1ff6122733e17361d36a7b --- server/PlayerThread.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/PlayerThread.cpp b/server/PlayerThread.cpp index b7c385b5..2726418e 100644 --- a/server/PlayerThread.cpp +++ b/server/PlayerThread.cpp @@ -47,10 +47,11 @@ PlayerThread::~PlayerThread() __playerAvailable = false; __playUtterance = nullptr; + __threadCond.notify_all(); + tryToStopPlayer(); SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Thread is stopped or waiting"); - __threadCond.notify_all(); __playerThread.join(); SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Finish thread"); } @@ -133,6 +134,7 @@ void PlayerThread::runPlayer() SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Wait playing"); if (isThreadStopped()) { __threadCond.wait(lock); + usleep(10000); } while (false == isThreadStopped()) { @@ -141,6 +143,7 @@ void PlayerThread::runPlayer() __playUtterance(this, uid); } + SLOG(LOG_INFO, tts_tag(), "[PlayerThread] notify stopCheckCond"); __stopCheckCond.notify_all(); } } -- 2.34.1