recursive_mutex的最大所有权的下限? [英] Lower bound for the maximum level of ownership for recursive_mutex?

查看:199
本文介绍了recursive_mutex的最大所有权的下限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用 [thread.mutex.recursive]


拥有 recursive_mutex 对象的线程可以通过调用 lock() try_lock()。未指定单个线程可以获取多少级别的所有权。如果线程已经获得了 recursive_mutex 对象的最大所有权级别,对 try_lock()的额外调用将​​失败,并且对 lock()的额外调用将​​引发类型 system_error 的异常。

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互斥体呢?

Is there a lower bound greater than 1 for the "maximum level of ownership"? What about recursive pthread mutexes?

推荐答案

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

There is no lower limit specified in the standard. This is probably deliberate.

旧标准(我认为)用来为这样的事情提供较低的限制。结果是人们编写编码标准,说你不能使用超过这些下限。例如:这是(我认为仍然是)实现定义外部符号的多少个字符在比较相等时有意义。因此, a_very_ouble_long_name_indeed_with_extra_padding a_very_very_long_name_indeed_with_extra_paddingX 可能被视为相同的符号。最小长度被指定为8,并且编码标准被写成指定外部符号的最大长度是八个字符。

Older standards (C I think) did use to provide lower limits for things like this. The result was that people wrote coding standards which said you couldn't use more than these lower limits. For example: It was (and I think still is) implementation defined how many characters of an external symbol were significant when comparing for equality. So a_very_very_long_name_indeed_with_extra_padding and a_very_very_long_name_indeed_with_extra_paddingX might be treated as the same symbol. The minimum length was specified as 8, and coding standards were written specifying "maximum length of a external symbol is eight characters".

在该值的合理的下限:我可以容易地想象,计数可能被打包成其他字段,以便整个事情可以用一个合适的指令进行原子性更新。因此,它可能是一个不到32位的交易。 (它只需要足够大的最大调用堆栈深度,因此在受限环境中,31可能是足够好的。)

On the plausible lower bound for this value: I can easily imagine that the count might be bit-packed into some other field so that the whole thing can be updated atomically with a suitable instruction. As such, it might be a good deal less than 32 bits. (It only really needs to be large enough for the maximum call stack depths, so in a constrained environment, 31 might be good enough.)

这篇关于recursive_mutex的最大所有权的下限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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