Possible Thread Starvation in C++
I have a decode
function that decodes a string and internally uses a map to store already-decoded values for efficiency. This function is accessed by multiple threads (using pthread
), so to prevent concurrent access issues with the map, I added a std::mutex
. However, after adding the mutex, I noticed that some threads eventually stop working or appear to get stuck. When I removed the mutex locks, all threads ran without any issues.