From 1284103b98c2b00ba6ac811e3977c68e08999bb3 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Thu, 6 Nov 2025 20:39:34 +0100 Subject: [PATCH] fix(AsyncNotificationCenter): hang on stop() #5059 --- Foundation/include/Poco/AsyncNotificationCenter.h | 5 +++++ Foundation/src/AsyncNotificationCenter.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Foundation/include/Poco/AsyncNotificationCenter.h b/Foundation/include/Poco/AsyncNotificationCenter.h index 27358fcab..a63f63dcc 100644 --- a/Foundation/include/Poco/AsyncNotificationCenter.h +++ b/Foundation/include/Poco/AsyncNotificationCenter.h @@ -120,6 +120,11 @@ private: using Adapter = RunnableAdapter; + class ShutdownNotification: public Notification + /// Internal notification used to signal the dequeue loop to stop. + { + }; + const AsyncMode _mode { AsyncMode::ENQUEUE }; // Async enqueue for notifications diff --git a/Foundation/src/AsyncNotificationCenter.cpp b/Foundation/src/AsyncNotificationCenter.cpp index 0458d41d3..4adb54261 100644 --- a/Foundation/src/AsyncNotificationCenter.cpp +++ b/Foundation/src/AsyncNotificationCenter.cpp @@ -180,6 +180,7 @@ void AsyncNotificationCenter::stop() { if (_enqueueThreadStarted.exchange(false)) { + _nq.enqueueUrgentNotification(new ShutdownNotification); _nq.wakeUpAll(); while (!_enqueueThreadDone) Thread::sleep(100); _enqueueThread.join(); @@ -207,8 +208,11 @@ void AsyncNotificationCenter::dequeue() Notification::Ptr pNf; _enqueueThreadStarted = true; _enqueueThreadDone = false; - while ((pNf = _nq.waitDequeueNotification())) + while (true) { + pNf = _nq.waitDequeueNotification(); + if (!pNf) break; + if (pNf.cast()) break; try { notifyObservers(pNf);