c++ - Will two overlapping mutexes lead to deadlock? -


consider following member functions. lead deadlock?

void foo::insert(item_ptr item) {      lock_guard<mutex> lock(mu_);      items_.insert(item); }   void foo::insert(vector<item_ptr> items) {       lock_guard<mutex> lock(mu_); // lead                                                         // deadlock?       for(auto item:items)             insert(item); } 

if mu_ std::mutex, have problem. std::mutex not support recursive locks , cannot locked twice same thread. see: http://en.cppreference.com/w/cpp/thread/mutex

if mu_ std::recursive_mutex, have no problem. thread can lock recursive mutex if has locked. see http://en.cppreference.com/w/cpp/thread/recursive_mutex


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -