thrd_busy 和 mtx_lock()/mtx_timedlock()

发布于 2024-11-15 02:11:33 字数 570 浏览 2 评论 0原文

我对 C1x 互斥体有以下问题 (§7.25.4):

在哪些情况下 mtx_lock() 可以返回 thrd_busy 而不是阻塞?在什么情况下mtx_timedlock()可以返回thrd_busy

请注意,thrd_busy 在 §7.25.1 ¶5 中定义为“当测试和返回函数请求的资源已在使用时”返回。

我希望 thrd_busy 仅由 mtx_trylock() 返回,或者最多也由 mtx_lock() 在使用 mtx_try 调用时返回mtx_try | mtx_recursive 互斥体,但绝对不是来自 mtx_timedlock(),它需要一个支持超时的互斥体,即 mtx_timedmtx_timed | mtx_recursive 互斥体。

这是否是草案的公正和疏忽?或者我错过了什么?

I have the following questions about C1x mutexes (§7.25.4):

In which situations can mtx_lock() return thrd_busy instead of blocking? In which situations can mtx_timedlock() return thrd_busy?

Note that thrd_busy is defined in §7.25.1 ¶5 as being returned "when a resource requested by a test and return function is already in use".

I would expect thrd_busy to be only returned by mtx_trylock(), or at most also by mtx_lock() when invoked with a mtx_try or mtx_try | mtx_recursive mutex, but definitely not from mtx_timedlock(), which requires a mutex which supports timeout, i.e. a mtx_timed or mtx_timed | mtx_recursive mutex.

Is this just and oversight in the draft? Or am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑白记忆 2024-11-22 02:11:33

如果互斥体不是递归的,但您尝试以递归方式锁定它,则行为未定义。然而,实现可以检测到这一点并返回 thrd_busy 。 (或者,它可能永远阻塞,或者返回thrd_error,或者thrd_success,或者格式化你的硬盘......)

If the mutex is not recursive, but you try to lock it in a recursive manner then the behaviour is undefined. However, an implementation could detect this and return thrd_busy. (Alternatively, it may block forever, or return thrd_error, or thrd_success, or format your hard disk.....)

南烟 2024-11-22 02:11:33
  1. mtx_lock() 不返回 thrd_busy,但是,如果请求的资源已在使用中,mtx_trylock 函数将返回 thrd_busy。
  2. mtx_timedlock() 不返回 thrd_busy。如果成功,mtx_timedlock 函数返回 thrd_success;如果达到指定的时间而没有获取请求的资源,则返回 thrd_timedout;如果无法满足请求,则返回 thrd_error。
  1. mtx_lock() does not return thrd_busy, however, the mtx_trylock function returns thrd_busy if the resource requested is already in use.
  2. mtx_timedlock() does not return thrd_busy. The mtx_timedlock function returns thrd_success on success, or thrd_timedout if the time specified was reached without acquiring the requested resource, or thrd_errorif the request could not be honored.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文