std::timed_mutex包含在<mutex>头文件中。

用法和std::mutex类似。

1 std::chrono::milliseconds timeout(100); 2 if (my_mymutex.try_lock_for(timeout)){ 3 //......拿到锁返回ture 4 } 5 else{ 6 std::chrono::milliseconds sleeptime(100); 7 std::this_thread::sleep_for(sleeptime); 8 }
1 std::chrono::milliseconds timeout(100); 2 if (my_mymutex.try_lock_until(chrono::steady_clock::now() + timeout)){ 3 //......拿到锁返回ture 4 } 5 else{ 6 std::chrono::milliseconds sleeptime(100); 7 std::this_thread::sleep_for(sleeptime); 8 }
https://blog.csdn.net/qq_38231713/article/details/106093490
【C++多线程】std::timed_mutex带超时的互斥量
原文:https://www.cnblogs.com/chen-cs/p/13254411.html