Is there a final example of using a mutex under boost 1.48.0?

Most of the examples I found on the Internet are deprecated using boost :: mutex, which I could not declare, including or. Is there a clear example of how to use boost :: mutex in version 1.48.0? The tutorials in chapter 27 (Themes) are very obscure and contain no code examples.

+6
source share
1 answer

Check out this example ( boost::mutex usage is presented in Resource::use() ):

 #include <boost/thread.hpp> #include <boost/bind.hpp> class Resource { public: Resource(): i(0) {} void use() { boost::mutex::scoped_lock lock(guard); ++i; } private: int i; boost::mutex guard; }; void thread_func(Resource& resource) { resource.use(); } int main() { Resource resource; boost::thread_group thread_group; thread_group.create_thread(boost::bind(thread_func, boost::ref(resource))); thread_group.create_thread(boost::bind(thread_func, boost::ref(resource))); thread_group.join_all(); return 0; } 
+13
source

Source: https://habr.com/ru/post/901762/


All Articles