加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 对共享内存使用无锁算法

发布时间:2020-12-16 07:01:12 所属栏目:百科 来源:网络整理
导读:我想对共享内存使用无锁算法来避免互斥.我有一些共享数据的进程使用共享内存.如果进程锁定互斥锁并崩溃,则所有其他进程也会崩溃. 我读了一些用链表实现无锁算法的论文.但是在我的共享内存中,我无法定义在此内存块上使用的数据结构.我只有一个指向这个块的指
我想对共享内存使用无锁算法来避免互斥.我有一些共享数据的进程使用共享内存.如果进程锁定互斥锁并崩溃,则所有其他进程也会崩溃.

我读了一些用链表实现无锁算法的论文.但是在我的共享内存中,我无法定义在此内存块上使用的数据结构.我只有一个指向这个块的指针.

所以我对在我的情况下应用无锁算法没有任何想法.我需要你的一些帮助.如果我的英语非常糟糕,谢谢,抱歉.

解决方法

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().

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读