diff --git a/src/BackgroundThread.cpp b/src/BackgroundThread.cpp index 54adcc3..7b2a59e 100644 --- a/src/BackgroundThread.cpp +++ b/src/BackgroundThread.cpp @@ -14,10 +14,14 @@ BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread: } BackgroundThread::~BackgroundThread() { - DEBUG_FUNCTION_LINE("Shutting down FTP Server"); - stopThread(); - while (!hasThreadStopped()) { - OSSleepTicks(OSMillisecondsToTicks(10)); + if (!isThreadTerminated()) { + DEBUG_FUNCTION_LINE("Shutting down FTP Server"); + stopThread(); + while (!hasThreadStopped()) { + OSSleepTicks(OSMillisecondsToTicks(10)); + } + } else { + DEBUG_FUNCTION_LINE_WARN("Thread is already terminated"); } if (this->serverSocket >= 0) { cleanup_ftp(); diff --git a/src/utils/CThread.h b/src/utils/CThread.h index 2d89ccd..90b1bfc 100644 --- a/src/utils/CThread.h +++ b/src/utils/CThread.h @@ -89,7 +89,7 @@ public: } //! Check if thread is terminated - [[nodiscard]] virtual BOOL isThreadTerminated() const { + [[nodiscard]] BOOL isThreadTerminated() const { if (pThread) return OSIsThreadTerminated(pThread); return false; }