boost::recursive_mutex m;
m.lock();
versus
boost::lock_guard<boost::recursive_mutex> lock( mutex_ );
Is there an advantage to use the first Form? Does the second form only provide RAII mecanism, or are there others advantages ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The advantage of using lock_guard is that it will release the lock when it goes out of scope. This eliminates the need to manually release the lock and reduces the chance of forgetting to do so.