更新时间:2022-06-09 20:56:51
std :: condition_variable
因此当您不需要 std :: condition_variable_any
的灵活性时,可以更高效。
std::condition_variable
is more specialized, and therefore can be more efficient when you don't need the flexibility of std::condition_variable_any
.
从N3290§30.5[thread.condition] / 1
From N3290 §30.5[thread.condition]/1
类
condition_variable
提供
a只能等待类型unique_lock< mutex>
的对象的条件变量,允许在某些平台上最大化
的效率。类condition_variable_any
提供了一个一般的条件变量,
可以等待用户提供的锁类型的对象。
Class
condition_variable
provides a condition variable that can only wait on an object of typeunique_lock<mutex>
, allowing maximum efficiency on some platforms. Classcondition_variable_any
provides a general condition variable that can wait on objects of user-supplied lock types.
事实上,在LLVM的libc ++中, condition_variable_any
是使用更专业的 condition_variable
它使用pthread_cond_t)在shared_mutex上。
Actually, in LLVM's libc++, condition_variable_any
is implemented using the more specialized condition_variable
(which uses pthread_cond_t) on a shared_mutex.