Is a mutex defined statically in a function body able to lock properly? I am currently using this pattern in my logger system, but I have not tested it's thread safety yet.
I am using C++11 and I have a std::thread which is a class member, and it sends information to listeners every 2 minutes. Other that that it just sleeps. So, I have made it sleep for 2 minutes, then send the required info, and then sleep for 2 minutes again.
I am using C++ 11 and I have an std::thread which is a class member and it sends a necessary info piece to listeners in every 2 minutes. Other that that it just sleeps. So, I have made it to sleep for 2 minutes and then send the required info...
I have a multi threaded C++ program which simulates a car workshop. Basically a car is a thread here and a station is a resource. It works like this: Car enters a workshop and it has a list of stations (just ints), that it has to visit, to get repaired....
Using cout in multiple threads might result in interleaved output. So I tried to protect cout with a mutex.
Moving forward with Concurrency In Action I have reached the following example. Tha author states that if we everytime lock 2 mutexes in the same order, then we are guaranteed to avoid deadlocks. Consider this example from the book:
Here we are:Do we really need to lock mutex in the get function? We are only providing read only access. What if we do not?