Skip to content

Commit 1830e42

Browse files
bmehta001Copilot
andcommitted
Improve WorkerThread shutdown diagnostics
- Replace catch(...) with specific std::system_error and std::exception handlers that log error code and message via LOG_ERROR - Move queue-depth LOG_WARNs outside the joined-only block so the detach path also reports pending work at shutdown Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d26beaf commit 1830e42

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

‎lib/pal/WorkerThread.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "pal/WorkerThread.hpp"
77
#include "pal/PAL.hpp"
88

9+
#include <system_error>
10+
911
#if defined(MATSDK_PAL_CPP11) || defined(MATSDK_PAL_WIN32)
1012

1113
/* Maximum scheduler interval for SDK is 1 hour required for clamping in case of monotonic clock drift */
@@ -65,19 +67,27 @@ namespace PAL_NS_BEGIN {
6567
m_hThread.detach();
6668
}
6769
}
68-
catch (...) {};
70+
catch (const std::system_error& e) {
71+
LOG_ERROR("Thread join/detach failed: [%d] %s", e.code().value(), e.what());
72+
}
73+
catch (const std::exception& e) {
74+
LOG_ERROR("Thread join/detach failed: %s", e.what());
75+
}
76+
77+
// Log pending work in both paths so operators can see if
78+
// shutdown is dropping tasks.
79+
if (!m_queue.empty()) {
80+
LOG_WARN("Shutdown with %zu queued task(s) pending", m_queue.size());
81+
}
82+
if (!m_timerQueue.empty()) {
83+
LOG_WARN("Shutdown with %zu timer(s) pending", m_timerQueue.size());
84+
}
6985

7086
// Clean up any tasks remaining in the queues after shutdown.
7187
// Only safe after join() — the thread has fully exited.
7288
// After detach(), the thread still needs the shutdown item
7389
// and may still be accessing the queues.
7490
if (joined) {
75-
if (!m_queue.empty()) {
76-
LOG_WARN("Shutdown with %zu queued task(s) pending", m_queue.size());
77-
}
78-
if (!m_timerQueue.empty()) {
79-
LOG_WARN("Shutdown with %zu timer(s) pending", m_timerQueue.size());
80-
}
8191
for (auto task : m_queue) { delete task; }
8292
m_queue.clear();
8393
for (auto task : m_timerQueue) { delete task; }

0 commit comments

Comments
 (0)