Martin Sebor
2010-04-30 18:23:26 UTC
I'm wondering whether calling pthread_mutex_destroy on a mutex
object initialized using the PTHREAD_MUTEX_INITIALIZER macro is
necessary (or even a good idea) in dynamically loadable shared
libraries.
The specific use case that I have in mind is a library that is
repeatedly opened and closed by a process, and that contains
such a mutex object as an implementation detail.
When the library is first opened (via dlopen()), the mutex is
initialized. If, however, a process destroys the mutex before
closing the library and then proceeds to close and open it
again, is it safe to assume that the mutex will be correctly
re-initialized? If the process doesn't destroy the mutex, does
it risk leaking resources?
Since dlclose() is allowed but not required to actually unload
the library, it's not clear to me what assumptions are safe to
to make about the state of the mutex after reloading it.
Thanks
Martin
object initialized using the PTHREAD_MUTEX_INITIALIZER macro is
necessary (or even a good idea) in dynamically loadable shared
libraries.
The specific use case that I have in mind is a library that is
repeatedly opened and closed by a process, and that contains
such a mutex object as an implementation detail.
When the library is first opened (via dlopen()), the mutex is
initialized. If, however, a process destroys the mutex before
closing the library and then proceeds to close and open it
again, is it safe to assume that the mutex will be correctly
re-initialized? If the process doesn't destroy the mutex, does
it risk leaking resources?
Since dlclose() is allowed but not required to actually unload
the library, it's not clear to me what assumptions are safe to
to make about the state of the mutex after reloading it.
Thanks
Martin