
Hello all, I have a set of modules (ie classes, say the Module class and some Module derived classes) which calculate (or generate) data, and two different module instances could be connected together: one would use as input data the output of the other one. I have also a class which manages (say the ModulesManager class) the interconnections of those modules and it triggers the calculation of all the modules. The calculation is triggered in an worker boost::thread at a given rate (i.e. when the ModulesManager::trig () method is called). The modules have an internal state (upon which its calculation is based on), which could be changed by another thread calling some method of the Module class, say Module::setOffset(int offset). The problem is that I would like that any change to the internal state of any module happen not when the network of modules is being triggered by the ModulesManager, but it could be possible only between a call to trig() and its subsequent call. I would like to have a suggestion on how to modelize that in an elegant way. I thought about using something like the following: struct ModulesManager { ModulesManager::trig () { recursive_mutex::scoped_lock (*mutex); for (each Module mod) { mod->calculate (....); }//for } shared_ptr<recursive_mutex> ModulesManager::getMutex () const {return mutex;} } Then any thread could change the internal state of any Module just by using a code such as: AnyClassRunningInAnotherThread::setModuleXInternalState () { recursive_mutex::scoped_lock (*modulesManagerInstance->getMutex ()); moduleX->setOffset (newOffset); } Thanks in advance for any better proposal, Luca