简体   繁体   English

pthread_mutex和进程终止

[英]pthread_mutex and process termination

Before using a pthread_mutex_t pthread_mutex_init() should be called, and after it's not longer required it should be destroyed using pthread_mutex_destroy(). 在使用pthread_mutex_t之前,应调用pthread_mutex_init(),并且在不再需要它之后,应使用pthread_mutex_destroy()销毁它。

My question is, what happens if my process terminates before it can call pthread_mutex_destroy(), for example a SIGKILL, SIGINT or SIGABORT? 我的问题是,如果我的进程在调用pthread_mutex_destroy()之前终止会发生什么,例如SIGKILL,SIGINT或SIGABORT? Is it possible that some resource will leak? 某些资源是否可能泄漏?

Same question goes to pthread_cond_init/destroy as well. 同样的问题也转到了pthread_cond_init / destroy。

Not on any platform you're likely to use. 不在您可能使用的任何平台上。 Objects like mutexes and condition variables are just chunks of memory in the process' address space. 像互斥体和条件变量这样的对象只是进程地址空间中的内存块。 When a process terminates, its address space ceases to exist. 当进程终止时,其地址空间不再存在。 So it's not possible for any resources to leak. 所以任何资源都不可能泄漏。

Process-shared resources are more complex. 流程共享资源更复杂。 While the resources won't leak, they may still exist and may even still be in use by other processes. 虽然资源不会泄漏,但它们可能仍然存在,甚至可能仍被其他进程使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM