c - pthread_mutex 和进程终止

标签 c linux multithreading pthreads

在使用 pthread_mutex_t 之前,应该调用 pthread_mutex_init(),在不再需要它之后,应该使用 pthread_mutex_destroy() 销毁它。

我的问题是,如果我的进程在调用 pthread_mutex_destroy()(例如 SIGKILL、SIGINT 或 SIGABORT)之前终止,会发生什么情况?是否有可能某些资源会泄漏?

同样的问题也适用于 pthread_cond_init/destroy。

最佳答案

不在您可能使用的任何平台上。互斥体和条件变量等对象只是进程地址空间中的内存块。当进程终止时,其地址空间不再存在。因此任何资源都不可能泄漏。

进程共享资源更加复杂。虽然资源不会泄漏,但它们可能仍然存在,甚至可能仍在被其他进程使用。

关于c - pthread_mutex 和进程终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54974793/

相关文章:

c++ - valgrind 使用 --trace-children=yes 得到的结果不正确

c - 在 C 中将多个字符串分组为一个

c - K&R C 书给我编译问题

linux - 在 Windows 上运行虚拟机

python - 快速重新排列文本文件

c - 在 C 中使用 Pthread 库

linux - Eclipse 的一个窗口中的 Bash shell

linux - 如何通过 ssh 登录到 Ubuntu 并自动执行 sudo su?

python - python hdf5解析函数多线程时速度没有提升

multithreading - 在valgrind下运行的程序中断时的线程堆栈回溯