- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
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 returnfalse
even if the mutex was not locked by any other thread at some point duringtimeout_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 spurious 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 spurious 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 spurious 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, for example, 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* 虚假地失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33907999/
我的文件 test8.cpp是 #include #include #include std::mutex mutex; std::timed_mutex timed_mutex; 当我编译这段代码时
我第一次使用 timed_mutex。到目前为止,它对我来说只是 lock_guard。 但似乎只有第一个try_lock_for真正成功了。除了第一个 try_lock_for 之外的所有内容都返回
在哪些情况下会出现 std::timed_mutex优于常规互斥体? 我能想到的唯一用例是(IMO hackish)防止死锁的方法。 在哪些其他情况下 std::timed_mutex 是一个不错的选
我有一个问题。我想为我的程序使用互斥体。所以会发生什么:我正在构造一个包含 std::timed_mutex 的对象。创建时,此对象会锁定互斥量,因为稍后应将其解锁。创建互斥锁的同一线程现在应该等待该
我第一次使用 std::timed_mutex,它的行为与我预期的不同。它似乎立即失败,而不是等待互斥锁。我以毫秒为单位提供锁定超时(如此处所示 http://www.cplusplus.com/re
try_lock* 是指 try_lock()、try_lock_for() 和 try_lock_until()。根据cppreference ,这三种方法都可能会虚假地失败。以下引用自 try_l
我正在尝试同时使用 timed_mutex 和 scoped_lock。我之前通过一些示例成功地使用了 scoped_lock,但现在我似乎找不到解决方法,我也无法正确理解 boost 文档。 期望的
我在 Ubuntu 12.04 中使用 gcc-4.8.1(configure: ./configure --prefix=/usr/local) 编译了以下代码,但是当我运行它时,它没有工作。它没有
根据 Boost 文档,boost::mutex 和 boost::timed_mutex 应该是不同的。第一个实现了 Lockable Concept,第二个实现了 TimedLockable Co
我需要通过互斥来保护资源。为了改进诊断,我正在考虑使用 timed_mutex 进行死锁警告(代码未测试): boost::timed_mutex m; // first thread accessi
这可能吗?我想使用 timed_mutex 而不是带有 condition_variable 的常规互斥锁,但它不会编译并查看源代码 void wait(unique_lock& __lock
我想知道这两者之间的区别是什么 boost::timed_mutex _mutex; if(_mutex.timed_lock(boost::get_system_time() + boost::po
我是一名优秀的程序员,十分优秀!