c – std :: timed_mutex :: try_lock *虚假的失败

c – std :: timed_mutex :: try_lock *虚假的失败,第1张

概述通过try_lock *,我的意思是try_lock(),try_lock_for()和try_lock_until().根据 cppreference,所有这三种方法可能都是虚假的.以下是对try_lock_for()的描述引用 As with try_lock(), this function is allowed to fail spuriously and return false eve 通过try_lock *,我的意思是try_lock(),try_lock_for()和try_lock_until().根据 cppreference,所有这三种方法可能都是虚假的.以下是对try_lock_for()的描述引用

As with try_lock(),this function is allowed to fail spur@R_403_6928@sly and
return false even if the mutex was not locked by any other thread at
some point during timeout_duration.

我知道虚假的唤醒可能会发生在std :: condition_variable和它背后的理由.但是,互斥体的情况如何?

解决方法 根据: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3209.htm

On the other hand,there are strong reasons to require that programs be written to tolerate spur@R_403_6928@s try_lock() failures:

As pointed out in Boehm,Adve,“Foundations of the C++ Concurrency Memory Model”,PLDI 08,enforcing sequential consistency for data-race-free programs without spur@R_403_6928@s try_lock() failures requires significantly stronger memory ordering for lock() operations on try_lock()-compatible mutex types. On some architectures that significantly increases the cost of uncontended mutex acquisitions. This cost appears to greatly outweigh any benefit from prohibiting spur@R_403_6928@s try_lock() failures. It allows a user-written try_lock() to fail if,for example,the implementation fails to acquire a low-level lock used to protect the mutex data structure. Or it allows such an operation to be written directly in terms of compare_exchange_weak. It ensures that clIEnt code remains correct when,a deBUGging thread is introduced that occasionally acquires locks in order to be able to read consistent values from a data structure being checked or examined. Any code that obtains information from try_lock() failure would break with the introduction of another thread that purely locks and reads the data structure.
总结

以上是内存溢出为你收集整理的c – std :: timed_mutex :: try_lock *虚假的失败全部内容,希望文章能够帮你解决c – std :: timed_mutex :: try_lock *虚假的失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1254162.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存