Commit a26fa8dc authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Upon destruction, sigslot signals now wait for the signal_manager's signal...

Upon destruction, sigslot signals now wait for the signal_manager's signal queue to be flushed. This avoids crashed due to the signal_manager processing dangling signals, which have been deleted while being in the queue.
parent cbd7bcc6
......@@ -98,6 +98,36 @@ namespace sigslot {
_handlingMode = mode;
void signal_manager::waitForSignalQueueFlushed() {
// nothing to wait for if current thread is signal_manager's thread.
if (isCurrentThreadSignalManagerThread())
// nothing to wait for if the signal queue is already empty.
if (_signalQueue.empty())
class SIGSLOT_API flushed_signal : public _signal_handle_base {
flushed_signal(bool* ptr)
: _ptr(ptr)
~flushed_signal() {}
virtual void processSignal() const {
*_ptr = true;
bool* _ptr;
bool signalVariable = false;
this->queueSignalImpl(new flushed_signal(&signalVariable));
while (! signalVariable)
std::this_thread::yield(); // so we do some busy waiting here - hopefully not too long...
const std::string signal_manager::loggerCat_;
......@@ -346,6 +346,13 @@ namespace sigslot {
/// \see Runnable:run
virtual void run();
* Halts the calling thread until the current signal queue has been flushed.
* Flushing means that all signals currently in the signal queue have been fully handled.
void waitForSignalQueueFlushed();
/// Private constructor only for singleton
......@@ -444,6 +451,11 @@ namespace sigslot {
class SIGSLOT_API _signal_base
~_signal_base() {
if (signal_manager::isInited())
virtual void slot_disconnect(has_slots* pslot) = 0;
virtual void slot_duplicate(has_slots const* poldslot, has_slots* pnewslot) = 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment