I have a very simple (sample) C program as follows. I want to ensure I release any resources necessary so that valgrind does not complain. Do I need to free mutex1? Or do anything before the program terminates? Or is the mutex1 not allocate memory?
02 pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
03 int counter=0;
04
05 /* Function C */
06 void functionC()
07 {
08 pthread_mutex_lock( &mutex1 );
09 counter++
10 pthread_mutex_unlock( &mutex1 );
11 }
No, it is fine as it is. It is not necessary to use pthread_mutex_destroy on a statically allocated mutex.