- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个托管共享内存段,它有一个 boost::interprocess::interprocess_mutex 和一个 boost::interprocess::interprocess_condition 变量。我有 2 个进程访问共享内存,它们正在根据互斥锁和条件同步访问。我遇到过一个情况,我的第一个进程在 notify_all 方法上阻塞,最初我认为这是一个非阻塞方法,但似乎进程间条件实现了一个用于同步自身的互斥体。
我遇到这个死锁的情况是当进程 2 在等待条件时被不正常地杀死,我相信这会阻止条件互斥锁被解锁,然后当我再次运行进程 2 时它会阻塞。有没有办法在我第二次启动进程 2 时重置或清理进程间条件。
最佳答案
http://www.boost.org/doc/libs/1_48_0/boost/interprocess/sync/interprocess_mutex.hpp
你在使用定时锁定吗?
有关简单的死锁避免算法,请查看此处:Wikipedia
它适用于线程,但我相信它可以与 interprocess_locks 一起使用。
Recursively, only one thread is allowed to pass through a lock. If other threads enter the lock, they must wait until the initial thread that passed through completes n number of times. But if the number of threads that enter locking equal the number that are locked, assign one thread as the super-thread, and only allow it to run (tracking the number of times it enters/exits locking) until it completes. After a super-thread is finished, the condition changes back to using the logic from the recursive lock, and the exiting super-thread
sets itself as not being a super-thread
notifies the locker that other locked, waiting threads need to re-check this condition
If a deadlock scenario exists, set a new super-thread and follow that logic. Otherwise, resume regular locking.
请注意,上述算法无法解决活锁 情况,为防止此类行为,请尽可能使用信号量
。
我惊奇地发现 interprocess_mutex 不支持实现死锁避免算法,因为这些天以来,大多数互斥锁,即 std::mutex
和 boost::mutex
已经支持.我想这是操作系统特定的限制。
For more flexibility try using a named_upgradable_mutex
使用定时锁在进程崩溃时捕获异常并删除可升级的互斥锁!。此类型还允许任一线程获得 boost 的权限!
关于c++ - boost notify_all 上的进程间条件阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18240263/
根据 Android docs ,activity生命周期如下: onCreate() onStart() onResume() onPause() onStop() onDestroy() 问题是,
我有一门类(class)有很多专栏,但这个问题只需要其中三个: ---------------------------------------- | start_date | start_time
给定在同一个 Tomcat 6 上运行的两个 Web 应用程序。如果您从一个应用程序到另一个应用程序进行 http 调用,Tomcat 是否会“短路”此调用,或者它会在调用之前一直在 interweb
我是一名优秀的程序员,十分优秀!