c++ - recursive_mutex 的最大所有权级别的下限?

标签 c++ pthreads language-lawyer recursive-mutex

引用 [thread.mutex.recursive] :

A thread that owns a recursive_mutex object may acquire additional levels of ownership by calling lock() or try_lock() on that object. It is unspecified how many levels of ownership may be acquired by a single thread. If a thread has already acquired the maximum level of ownership for a recursive_mutex object, additional calls to try_lock() shall fail, and additional calls to lock() shall throw an exception of type system_error.

所有权的最高级别”是否有大于 1 的下限?递归 pthread 互斥锁怎么样?

最佳答案

标准中没有规定下限。这可能是故意的。

较旧的标准(我认为是 C)确实用于为此类事情提供下限。结果是人们编写了编码标准,规定您不能使用超过这些下限的值。例如:它曾经(我认为现在仍然是)实现定义了在比较相等时外部符号的多少个字符是重要的。所以 a_very_very_long_name_indeed_with_extra_paddinga_very_very_long_name_indeed_with_extra_paddingX 可能被视为相同的符号。最小长度被指定为 8 个字符,并且编写了编码标准来指定“外部符号的最大长度为八个字符”。

关于这个值的合理下限:我可以很容易地想象这个计数可能被打包到其他一些字段中,这样整个事情就可以用一个合适的指令自动更新。因此,少于 32 位可能会很划算。 (它只需要足够大以支持最大调用堆栈深度,因此在受限环境中,31 可能就足够了。)

关于c++ - recursive_mutex 的最大所有权级别的下限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37203741/

相关文章:

c++ - 嵌套类的类内 friend 是否可以访问外部类成员?

c++ - C++ 中::运算符的规则

c++ - 无法在 Spirit::Qi 中定义规则

c++ - 创建信号和槽 qt4 gui builder

c++ - 为什么显示vector<long double>时看不到所有有效数字?

c - pthread_cond_timedwait 忽略取消请求

c - 如何等待任何/所有 pthread 完成?

c++ - 互斥体上的条件断点未触发

c++ - 什么时候可以安全且轻松地将引用变量用作别名?

c - 未命名结构的灵活数组成员