c++timeroopobject-destruction

C++: Callbacks and system timer events during destructor cascade


Assume an OO design where objects call each other, and after a while the called upon objects callback the initiating objects (calls and callbacks). During normal program termination, while destructors are called, is there some kind of promise that no system timers will be called, and no object will initiate a callback?


Solution

  • There is a pretty awesome library to handle these kinds of calls, and of course it's a Boost one.

    Behold Boost.Signals2, with guarantees of correctness even in multi-threaded application :)

    Note in particular the use of boost::trackable class, so that objects destruction automatically invalidate the calls before they happen.

    Note: Boost.Signals (its ancestor) has pretty much the same functionality, but isn't thread-safe