简体   繁体   English

std :: lock_guard <pthread_mutex_t> 不编译

[英]std::lock_guard<pthread_mutex_t> does not compile

std::lock_guard<pthread_mutex_t> lock(mExecutionReportsLock);

This does not compile because pthread_mutex_t is not valid template argument. 由于pthread_mutex_t不是有效的模板参数,因此无法编译。 What is the best way to achieve this functionality 什么是实现此功能的最佳方法

std::mutex m;

auto my_lock = std::unique_lock<std::mutex>(m);

or... 要么...

using mutex_type = std::mutex;
using lock_type = std::unique_lock<mutex_type>;

mutex_type m;

auto lock = lock_type(m);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM