[Pvfs2-developers] gen_mutex_destroy

Sam Lang slang at mcs.anl.gov
Fri Apr 13 15:07:52 EDT 2007


Hi All,

Quick question about mutexes.  Right now we have:

gen_mutex_t * gen_mutex_build();
gen_mutex_init(gen_mutex_t *mut);
gen_mutex_destroy(gen_mutex_t *mut);

Obviously, gen_mutex_build allocates space for the mutex and  
initializes it.  gen_mutex_init just calls pthread_mutex_init.  The  
problem I have is with gen_mutex_destroy.  It assumes that the passed  
in mutex was returned from gen_mutex_build(), and so frees it after  
calling pthread_mutex_destroy.   Essentially, if our code uses  
gen_mutex_init (pthread_mutex_init), our code never calls  
gen_mutex_destroy (or pthread_mutex_destroy).  This seems to be ok  
for the linux impl, which doesn't appear to require cleanup.  Also,  
it doesn't look like we ever re-initialize mutexes more than once.   
Semantically though, there's no good way to call  
pthread_mutex_destroy on a mutex we initialized with gen_mutex_init,  
and so we're not following the pthread spec exactly.

Honestly, I don't think there are any good cases in the code where  
gen_mutex_build() couldn't just be gen_mutex_init.  So I'm tempted to  
just replace those pointers with just the gen_mutex_t in-place, and  
call gen_mutex_init instead of gen_mutex_build.  Then  
gen_mutex_destroy could just call pthread_mutex_destroy without  
freeing the pointer.

Does this seem reasonable?  Or should I just ignore the fact that my  
mutexes aren't being destroyed?

-sam


More information about the Pvfs2-developers mailing list