mutex mm2;
int cale = 0;
void shared_mutex_Test(string url)
{
while (true)
{
mm2.lock();
printf(“%s–>%d\n”, url.c_str(),cale);
cale++;
mm2.unlock();
Sleep(100);
}
}
int main2()
{
std::thread t1(shared_mutex_Test, “Thread1*”);
std::thread t2(shared_mutex_Test, “Thread2*”);
t2.join();
t1.join();
}
同个线程多次调用mutex.lock,在没有unclok的时候,继续lock 并不会阻塞线程,而是线程崩溃,需要用share_mutex