[Development] qt_add/removeObject hooks

Matthew Woehlke mw_triad at users.sourceforge.net
Tue Apr 15 15:49:53 CEST 2014


On 2014-04-09 03:24, Volker Krause wrote:
> - thread-safety: we might be setting the callback at a point where already
> several threads are active. For us it's less relevant that we don't miss a few
> calls from other threads there (attaching at runtime happens at an arbitrary
> point in time anyway), but that this doesn't crash the target application. We
> haven't observed issues with the signal spy callback so far, so probably only
> a theoretical issue (Marc, please don't hit me for this ;) ).

Just to point out, aligned writes to a pointer-sized value are generally 
thread safe without needing to do anything special; i.e. any reads will 
see the old value, or the new value, but never intermediate garbage. If 
you're concerned, you could always use an atomic intrinsic also to do 
the write. Since you're setting once, the extra cost should be pretty 
much ignorable.

> - multiple callback users: we would need to be reasonably sure nobody else but
> mutually exclusive debugging tools use those callbacks, especially not Qt. We
> kinda have this problem with the signal spy callback already, but luckily it's
> only needed by a rarely used feature in QtTestLib, so we don't clash there in
> practice. For GammaRay itself a single callback is perfectly fine, we have our
> own code to wrap that and dispatch it to multiple plug-ins anyway.

If you add the rule that callbacks can't be removed once registered, you 
could do an atomic exchange of the old callback for the new, and require 
that any attached callback calls the previously-registered callback 
also. (This would cost a compare per callback though in case the old is 
null.) This takes a small amount of cleverness at the call site to 
ensure that the pointer to old is written at the same time as the new 
callback is registered, but should be doable. (Depending on available 
intrinsics, you might need to do a CAS loop to first set your old, then 
register your own callback if no one else has done so in the mean time. 
Retry as needed. Under the circumstances, it's pretty unlikely you'd 
ever get stuck in an infinite loop doing this.)

-- 
Matthew




More information about the Development mailing list