From b2f0d316300de2d7e14888ab42e80f1913ccc8e8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 21 Nov 2021 04:06:30 +0100 Subject: [PATCH] Cont'd work on concurrent Signal, Connection destruction see also 992c72795998cb7aa2eb0900310c52a8e3f68379 and 7580d6aba7409ba7717cf35b549c3f2f5a610523 Spin to prevent race between d'tor setting `in_dtor` and acquiring Signal::_mutex. --- libs/pbd/pbd/signals.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libs/pbd/pbd/signals.py b/libs/pbd/pbd/signals.py index 34aab19ba6..7815004b24 100644 --- a/libs/pbd/pbd/signals.py +++ b/libs/pbd/pbd/signals.py @@ -309,21 +309,23 @@ def signal(f, n, v): \tvoid disconnect (boost::shared_ptr c) \t{ \t\t/* ~ScopedConnection can call this concurrently with our d'tor */ -\t\tif (!_in_dtor.load (std::memory_order_acquire)) { -\t\t\tGlib::Threads::Mutex::Lock lm (_mutex); +\t\tGlib::Threads::Mutex::Lock lm (_mutex, Glib::Threads::TRY_LOCK); +\t\twhile (!lm.locked()) { \t\t\tif (_in_dtor.load (std::memory_order_acquire)) { \t\t\t/* d'tor signal_going_away() took care of everything already */ \t\t\t\treturn; \t\t\t} -\t\t\t_slots.erase (c); -\t\t\tlm.release (); +\t\t\t/* Spin */ +\t\t\tlm.try_acquire (); +\t\t} +\t\t_slots.erase (c); +\t\tlm.release (); -\t\t\tc->disconnected (); +\t\tc->disconnected (); #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS -\t\t\tif (_debug_connection) { -\t\t\t\tstd::cerr << "------- DISCCONNECT " << this << " size now " << _slots.size() << std::endl; -\t\t\t\tPBD::stacktrace (std::cerr, 10); -\t\t\t} +\t\tif (_debug_connection) { +\t\t\tstd::cerr << "------- DISCCONNECT " << this << " size now " << _slots.size() << std::endl; +\t\t\tPBD::stacktrace (std::cerr, 10); \t\t} #endif \t}