我想对共享内存使用无锁算法来避免互斥.我有一些共享数据的进程使用共享内存.如果进程锁定互斥锁并崩溃,则所有其他进程也会崩溃.
我读了一些用链表实现无锁算法的论文.但是在我的共享内存中,我无法定义在此内存块上使用的数据结构.我只有一个指向这个块的指针.
所以我对在我的情况下应用无锁算法没有任何想法.我需要你的一些帮助.如果我的英语非常糟糕,谢谢,抱歉.
If a process is locking mutex and crashes,all other processes also crash.
特别针对此用例有robust mutexes:
PTHREAD_MUTEX_ROBUST
If the process containing the owning thread of a robust mutex terminates while holding the mutex lock,the next thread that acquires the mutex shall be notified about the termination by the return value [EOWNERDEAD] from the locking function. If the owning thread of a robust mutex terminates while holding the mutex lock,the next thread that acquires the mutex may be notified about the termination by the return value [EOWNERDEAD]. The notified thread can then attempt to mark the state protected by the mutex as consistent again by a call to pthread_mutex_consistent(). After a subsequent successful call to pthread_mutex_unlock(),the mutex lock shall be released and can be used normally by other threads. If the mutex is unlocked without a call to pthread_mutex_consistent(),it shall be in a permanently unusable state and all attempts to lock the mutex shall fail with the error [ENOTRECOVERABLE]. The only permissible operation on such a mutex is pthread_mutex_destroy().