Lower bound for the maximum level of ownership for recursive_mutex?

拟墨画扇 提交于 2019-12-22 13:09:31

问题


Quoting [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.

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


回答1:


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

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".

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.)



来源:https://stackoverflow.com/questions/37203741/lower-bound-for-the-maximum-level-of-ownership-for-recursive-mutex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!