会杀死进程/线程释放互斥锁吗?

时间:2021-04-18 20:25:11

Several processes access shared memory, locking it with the mutex and pthread_mutex_lock() for synchronization, and each process can be killed at any moment (in fact I described php-fpm with APC extension, but it doesn't matter).
Will the mutex be unlocked automatically, if the process locked the mutex and then was killed?
Or is there a way to unlock it automatically?

有几个进程访问共享内存,用互斥锁和pthread_mutex_lock()锁定它以进行同步,并且每个进程都可以随时被杀死(实际上我用APC扩展描述了php-fpm,但这没关系)。如果进程锁定互斥锁然后被杀死,那么互斥锁会自动解锁吗?或者有没有办法自动解锁?

Edit: As it turns out, dying processes and threads have similar behavior in this situation, which depends on robust attribute of mutex.

编辑:事实证明,在这种情况下,死亡进程和线程具有类似的行为,这取决于互斥锁的强健属性。

1 个解决方案

#1


1  

That depends on the type of mutex. A "robust" mutex will survive the death of the thread/process. See this question: POSIX thread exit/crash/exception-crash while holding mutex

这取决于互斥锁的类型。 “强大的”互斥锁将在线程/进程死亡后继续存在。看到这个问题:POSIX线程退出/崩溃/异常崩溃,同时持有互斥锁

The next thread that will attempt to lock it will receive a EOWNERDEAD error code

将尝试锁定它的下一个线程将收到EOWNERDEAD错误代码

Note: Collected information from the comments.

注意:从评论中收集的信息。

#1


1  

That depends on the type of mutex. A "robust" mutex will survive the death of the thread/process. See this question: POSIX thread exit/crash/exception-crash while holding mutex

这取决于互斥锁的类型。 “强大的”互斥锁将在线程/进程死亡后继续存在。看到这个问题:POSIX线程退出/崩溃/异常崩溃,同时持有互斥锁

The next thread that will attempt to lock it will receive a EOWNERDEAD error code

将尝试锁定它的下一个线程将收到EOWNERDEAD错误代码

Note: Collected information from the comments.

注意:从评论中收集的信息。