提高:如何监控僵局互斥和力释放的状态 [英] boost: how to monitor status of mutex and force release on deadlock
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/989795/example-for-boost-shared-mutex-multiple-reads-one-write\">Example升压shared_mutex(多次读取/一个写)?
我试图使用 shared_lock
和 unique_lock
从boost库来实现基本的读写器锁定的资源。然而,一些访问资源的线程必须简单地崩溃的可能性。我想创建另一个进程,给定一个互斥体,监控互斥并跟踪哪些进程锁定资源多久每个进程都有锁。的过程中也将强制过程释放锁是否具有比给定的时间周期的详细锁
I am trying to use the shared_lock
and unique_lock
libraries from boost to implement a basic reader-writer lock on a resource. However, some of the threads accessing the resource have the potential to simply crash. I want to create another process that, given a mutex, monitors the mutex and keep track of what processes locked the resource and how long each process have the lock. The process will also force a process to release its lock if it has the lock for more than a given period of time.
对如何处理这个问题的任何建议是极大的AP preciated!
Any suggestions on how to approach this problem is greatly appreciated!
推荐答案
如果您强制处理持有锁释放,那么你已经打败了锁的目的。试想一下,互斥 pSharedMem-&GT,M
保护访问内存的一些位 pSharedMem-&GT;的MyStuff
If you force the process holding the lock to release, then you have defeated the purpose of the lock. Imagine mutex pSharedMem->m
protects access to some bit of memory pSharedMem->mystuff
pSharedMem->m.get_lock() ;
sleep( LONG_TIME ) ;
// wake up, not knowing that your "deadlock detector"
// has released your mutex
pSharedMem->mystuff++ ; // oh-oh... access to shared memory
// without the guarding mutex held.
// Who knows what will happen!
pSharedMem->m.release_lock() ; // you may very well trap or hit some
// system specific error because
// the mutex is no longer held.
(写出明确地 GET_LOCK()
和 RELEASE_LOCK()
明确地突出了锁保持的范围)。
(written out explicitly with get_lock()
and release_lock()
to explicitly highlight the scope of the lock hold).
这篇关于提高:如何监控僵局互斥和力释放的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!