unique_lock中std::try_to_lock
时间: 2023-09-27 12:09:32 浏览: 166
C++11 并发指南之std::mutex详解
std::try_to_lock是std::unique_lock的一个构造函数参数,在使用中可以用于尝试上锁。当使用std::try_to_lock参数创建std::unique_lock对象时,对象会尝试上锁但不会阻塞线程。如果对象成功上锁,则owns_lock()函数返回true,反之返回false。这种方式可以用于避免线程阻塞,而是根据锁的可用性来采取相应的操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [c++之std::unique_lock, std::lock, std::scoped_lock及std::condition_variable](https://blog.csdn.net/weixin_44537992/article/details/122734223)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文