Reputation: 8092
As I see on some video about rust, it have something like this (I use c++ instead of rust to show idea):
template<typename T>
class Synchronized {
public:
Synchronized(T);
Something<T> get();
private:
std::mutex lock_;
};
and usage like this:
Synchronized<std::string> obj;
auto s = obj.get();
//after that you can work with s as with std::string
//and obj.lock_ in locked state, after s was destroyed
//obj.lock_ will be unlocked
Is boost
or some other C++ popular library have such pattern implementation?
Upvotes: 3
Views: 612
Reputation: 145259
The as-of-this-writing experimental boost::synchronized_value
appears to be what you're looking for.
Upvotes: 7