c++ - Is there a boost equivalent to this "safe_read" call -


i new boost threading (came win32 threading, has ruined me).

so i'm trying make more "raii" way check working loop should still going. made simple function:

template<typenamet>  t safe_read(const t& t,boost::mutex& mutex) {     boost::interprocess::scoped_lock lock(mutex);     return t; } 

is there boost equivalent this, since seems i'd use time? acceptable call?

the idea able safely without using weirder lock:

while(!safe_read(this->is_killing_,this->is_killing_mutex_)) {     dowork(); } 

boost::atomic<bool> added in boost v1.53.0, based on c++11 std::atomics. example:

#include <boost/atomic.hpp>  boost::atomic<bool> is_killing (false);  while (!is_killing) { } 

this eliminate explicit mutex , safe_access function code, providing synchronization required.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -