Fix race condition when player thread is terminated
authorwn.jang <wn.jang@samsung.com>
Fri, 29 Dec 2023 05:43:59 +0000 (14:43 +0900)
committerwn.jang <wn.jang@samsung.com>
Tue, 2 Jan 2024 08:45:10 +0000 (17:45 +0900)
Change-Id: I1db88e6f4f308e59eb1ff6122733e17361d36a7b

server/PlayerThread.cpp

index b7c385b54c5f7001ae409f023a86b5dc3fa3bdf7..2726418e43c2c0b0c4b16e723ea900c80ccc6735 100644 (file)
@@ -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();
        }
 }