I've found that often in my code I have a need for primitive variables protected with synchronization objects such as a boost::mutex, and I was wondering if the boost library provides a template similar to this one I'm considering, based on the C# property methods get/set:
template<typename var_type>
class ThreadSafeVariable{
boost::mutex mut;
var_type value;
public:
var_type get(){
boost::mutex::scoped_lock(mut);
return value;
}
void set(var_type newValue){
boost::mutex::scoped_lock(mut);
value = newValue;
}
};