在Unix中崩溃时自动释放互斥锁 [英] Automatically release mutex on crashes in Unix
问题描述
我有两个程序通过共享内存段进行交互.当使用该段进行读取或写入时,它们持有一个锁.
I have two programs interacting via a shared memory segment. When using the segment for read or write, they hold a lock.
如果他们中的任何一个在关键部分崩溃(通常会被杀死-可能有不可捕获的东西),我希望他们释放锁定,以使shmem不会被完全锁定.
Should either of them crash (get killed, typically - possibly with something untrappable) in a critical section, I would like them to release the lock so that the shmem isn't locked out completely.
其他问题为Windows,Java等提供了答案,但是如何在Unix(特别是Linux)中实现呢?
Other questions point the way to the answer in Windows, Java, etc. but how do you do it in Unix (and specifically Linux)?
(我没有附加到pthreads互斥函数; SysV信号量或其他任何方法都可以.)
(I'm not attached to the pthreads mutex functions; SysV semaphores or anything else will do just fine.)
推荐答案
我相信您正在寻找POSIX健壮的互斥体:
I believe POSIX robust mutexes are what you're looking for:
http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getrobust.html
这篇关于在Unix中崩溃时自动释放互斥锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!