c++ - Why locking a std::mutex doesn't block the thread -


i wrote following code test understanding of std::mutex

int main() {     mutex m;     m.lock();     m.lock(); // expect block thread } 

and got system_error: device or resource busy. isn't second m.lock() supposed block thread?

from std::mutex:

a calling thread must not own mutex prior calling lock or try_lock.

and std::mutex::lock:

if lock called thread owns mutex, program may deadlock. alternatively, if implementation can detect deadlock, resource_deadlock_would_occur error condition may observed.

and exceptions clause:

throws std::system_error when errors occur, including errors underlying operating system prevent lock meeting specifications. mutex not locked in case of exception being thrown.

therefore not supposed block thread. on platform, implementation appears able detect when thread owner of lock , raise exception. may not happen on other platforms, indicated in descriptions.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -