【发布时间】:2019-03-03 23:19:17
【问题描述】:
在使用 pthread_mutex_t 之前,应调用 pthread_mutex_init(),在不再需要它之后,应使用 pthread_mutex_destroy() 将其销毁。
我的问题是,如果我的进程在调用 pthread_mutex_destroy()(例如 SIGKILL、SIGINT 或 SIGABORT)之前终止会发生什么?是否有可能某些资源会泄漏?
pthread_cond_init/destroy 也有同样的问题。
【问题讨论】:
-
您认为为什么会出现资源问题?互斥体只是用户空间中的一种数据结构。当进程终止时,所有内存都归还给操作系统。
-
你的进程还是线程?因为当进程终止时,所有线程都完成并释放资源。
-
@AlainMerigot,这就是我一直在寻找的答案,只是想确定一下。
-
@HoracioGoetendiaBonilla,就是这个过程。
标签: c linux multithreading pthreads