This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
stack allocation of pthread_mutex_t with initializer
- From: Godmar Back <godmar at gmail dot com>
- To: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Fri, 9 Aug 2013 13:19:03 -0400
- Subject: stack allocation of pthread_mutex_t with initializer
Hi,
I have a question about the semantics of PTHREAD_MUTEX_INITIALIZER/
pthread_mutex_destroy.
Is it required to call pthread_mutex_destroy on mutexes allocated as
automatic variables?
In other words, could the following code create a memory leak, in GNU
Libc or possibly in other conforming POSIX implementations?
void function_called_many_times() {
pthread_mutex_t M = PTHREAD_MUTEX_INITIALIZER;
// create threads, do work, use M
// M goes out of scope
}
Some online sources claim that PTHREAD_MUTEX_INITIALIZER can't be used
for automatic variables, but I've been unable to find an authoritative
source for that statement.
The POSIX standard explicitly wants to keep the mutex type opaque to
allow for both inlined & out of object implementations, but doesn't
address reclamation for mutexes declared using the static initializer
syntax.
- Godmar