On 2/17/07, Frank Mori Hess
Hi all,
I've finished thread_safe_signals. To get thread safety you have to include an additional header file thread_safe_signals/multi_threaded.hpp and set the last template parameter to boost::signals::multi_threaded.
-- Frank
I've been really trying to find time to take a look at all this new thread-safe-slot stuff, as I have tackled this same problems a few times myself (not with boost signals/slots, but various other similar ones). Maybe I can just do a few short comments/questions: - do you hold any locks DURING the slot call? That's typically bad, since you have no idea what else is locked or what a slot might do, so deadlocks abound. - do you copy the slot list before running through the list? - can I connect/disconnect during my slot call (either disconnect myself, or connect/disconnect other calls? If so, does it happen in this signal, or the next one?) - as for the 'lock per slot' vs 'lock per signal': The solution I've come up with in the past is basically lock per slot, but more importantly *temporary* lock per slot. ie you create (or take from a pool) locks as needed, and store them in a "slot -> lock" map, so IF another thread also needs the lock for that slot, they check the map first, and obtain the same lock for that slot. Using this, if you are careful, in most cases, you don't actually end up creating the lock at all (as you have all the information necessary to see contention as it is happening, and create the locks as needed. ie you know which slot is being called, and which slot is concurrently being disconnected, and only lock if they are the same - which means don't lock on the slot call, but AFTER the call, see if another thread has come in and is waiting for you to finish. So actually it is not a lock at all, but more of an 'event' (or a 'signal' but that'd be confusing). Not sure if that makes much sense (got a bit rambly there), but it is the seed of an idea that does work if you are careful... Hopefully I'll find some time to look at the new code in a week or two, but right now is the infamous 'crunch time'... - Tony