From 0efb67b51e0d9d34c65bbdbd9df567a8a991cc4c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 26 Apr 2014 22:11:23 +0200 Subject: DeferredMonitor: fix race condition when using GLib event loop Turns out the lock-free code using atomics was not thread-safe. The given callback could be invoked by GLib before the source_id attribute was assigned. This commit changes the DeferredMonitor class to use a Mutex to block the event loop until source_id is assigned. This bug does not exist in the 0.19 branch because it does not use the GLib main loop anymore. --- src/event/DeferredMonitor.hxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/event/DeferredMonitor.hxx') diff --git a/src/event/DeferredMonitor.hxx b/src/event/DeferredMonitor.hxx index 2380fb66f..2ac832a0a 100644 --- a/src/event/DeferredMonitor.hxx +++ b/src/event/DeferredMonitor.hxx @@ -27,6 +27,7 @@ #include "SocketMonitor.hxx" #include "WakeFD.hxx" #else +#include "thread/Mutex.hxx" #include #endif @@ -48,7 +49,9 @@ class DeferredMonitor #else EventLoop &loop; - std::atomic source_id; + Mutex mutex; + + guint source_id; #endif public: -- cgit v1.2.3