How would I lock a std::mutex
or boost::mutex
so at the start of my method I would lock it, but regardless of it already being locked or not just proceed with the code.
I want this kind of behaviour because there is going to be 2 threads that'll be reading and writing to an std::map
. When it's reading I just want to lock the mutex so that it can continue reading but the writing stops. When it's writing I want it to lock another mutex, which'll block reading and writing, and wait for both mutexes to be unlocked so that it can work with the map alone.