Fix race condition when player thread is terminated 13/303513/1
authorwn.jang <wn.jang@samsung.com>
Fri, 29 Dec 2023 05:43:59 +0000 (14:43 +0900)
committerwn.jang <wn.jang@samsung.com>
Fri, 29 Dec 2023 05:43:59 +0000 (14:43 +0900)
Change-Id: I1db88e6f4f308e59eb1ff6122733e17361d36a7b

server/PlayerThread.cpp

index cbaa095..ce7ccda 100644 (file)
@@ -48,10 +48,11 @@ PlayerThread::~PlayerThread()
        mPlayerAvailable = false;
        mPlayUtterance = nullptr;
 
+       mThreadCond.notify_all();
+
        tryToStopPlayer();
        SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Thread is stopped or waiting");
 
-       mThreadCond.notify_all();
        mPlayerThread.join();
        SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Finish thread");
 }
@@ -134,6 +135,7 @@ void PlayerThread::runPlayer()
                SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Wait playing");
                if (isThreadStopped()) {
                        mThreadCond.wait(lock);
+                       usleep(10000);
                }
 
                while (false == isThreadStopped()) {
@@ -142,6 +144,7 @@ void PlayerThread::runPlayer()
                        mPlayUtterance(this, uid);
                }
 
+               SLOG(LOG_INFO, tts_tag(), "[PlayerThread] notify stopCheckCond");
                mStopCheckCond.notify_all();
        }
 }