linux 进程 死锁,linux – 如何在UNIX上实际找到进程的死锁原因?

在unix上,一个进程被卡住,你怀疑它可能是死锁,找到死锁的原因以及如何删除和避免它?

我知道死锁的4个条件:

>相互排斥:资源最多可以分配给一个进程(不共享).

>保持并等待:允许持有资源的处理请求另一个.

>没有先发制人:进程必须释放其资源;他们不能被带走.

>循环等待:必须有一系列进程,以便链中的每个成员都在等待链的下一个成员持有的资源.

但是,它们是理论上的,如何确定unix实际上的死锁?

只有看到一个过程没有取得进展?

如何找到导致死锁的部分代码和原因?

如果您被允许使用工具,可以使用什么?

谢谢

解决方法:

Helgrind is a Valgrind tool for detecting synchronisation errors in C, C++ and Fortran programs that use the POSIX pthreads threading primitives.

The main abstractions in POSIX pthreads are: a set of threads sharing a common address space, thread creation, thread joining, thread exit, mutexes (locks), condition variables (inter-thread event notifications), reader-writer locks, spinlocks, semaphores and barriers.

Helgrind can detect three classes of errors, which are discussed in detail in the next three sections:

07001.

07002.

07003.

像这样的问题经常导致不可重现的,与时间相关的崩溃,死锁和其他不当行为,并且很难通过其他方式找到.

Helgrind知道所有的pthread抽象,并尽可能准确地跟踪它们的效果.在x86和amd64平台上,它理解并部分处理因使用LOCK指令前缀而产生的隐式锁定.

当您的应用程序仅使用POSIX pthreads API时,Helgrind效果最佳.但是,如果要使用自定义线程原语,可以使用helgrind.h中定义的ANNOTATE_ *宏来描述它们对Helgrind的行为.此功能已在Valgrind 3.5.0版中添加,并被视为实验性的.

标签:multithreading,linux,process,unix,deadlock

来源: https://codeday.me/bug/20190826/1732843.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值