std :: condition_variable和std :: condition_variable_any之间的区别是什么? [英] Whats the difference between std::condition_variable and std::condition_variable_any?

查看:976
本文介绍了std :: condition_variable和std :: condition_variable_any之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能缺少一些明显的东西,但我看不到 std :: condition_variable std :: condition_variable_any 。为什么我们需要两个?

I'm probably missing something obvious, but I can't see any difference between between std::condition_variable and std::condition_variable_any. Why do we need both?

推荐答案

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 type unique_lock<mutex>, allowing maximum efficiency on some platforms. Class condition_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.

这篇关于std :: condition_variable和std :: condition_variable_any之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆