2

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().

My question is, what happens if my process terminates before it can call pthread_mutex_destroy(), for example a SIGKILL, SIGINT or SIGABORT? Is it possible that some resource will leak?

Same question goes to pthread_cond_init/destroy as well.

Alberto Pires
  • 319
  • 1
  • 5
  • 10

1 Answers1

3

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.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278