Boost.mutex連續兩次加鎖會造成死鎖
阿新 • • 發佈:2019-02-07
問題程式碼如下:
#include<iostream> #include<iomanip> using namespace std; #include <boost/thread.hpp> #include <boost/bind.hpp> #include <boost/thread/mutex.hpp> using namespace boost; typedef boost::mutex CMutex; typedef boost::lock_guard<CMutex> CLockGuardMutex; typedef boost::thread_group CThreadGroup; void main() { CMutex oMutex; cout << "First Lock......" << endl; oMutex.lock(); cout << "Second Lock......" << endl; oMutex.lock(); cout << "Unlock Once......" << endl; oMutex.unlock(); cout << "Unlock Twice......" << endl; oMutex.unlock(); }