#include <iostream>
#include <thread>
#include <chrono>
#include <mutex>
std::mutex mtx;
int i = 0;
void func()
{
std::lock_guard<std::mutex> lock(mtx);
std::cout<<++i<<std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(8000));
}
int main() {
std::thread t1(func);
std::thread t2(func);
std::thread t3(func);
std::thread t4(func);
t1.join();
t2.join();
t3.join();
t4.join();
return 0;
}
Here is my c++ code. As you can see, only one thread has the chance to execute at any time because of the mutex. In other words, most of threads are blocked by the mutex.
My question is if there is some tool or some technique to detect how many threads are blocked by mutex in an executable file without reading the source code?