Sponsored Content
Top Forums Programming using pthread_mutex_destroy() Post 302176198 by JamesGoh on Monday 17th of March 2008 05:49:06 PM
Old 03-17-2008
using pthread_mutex_destroy()

As part of a multi-threaded code that I am designing, I am using mutexes to control access to a shared data segments in the code. I have no problems initalising and manipulating the mutexes to control access, however terminating the mutex itself is proving to be a bit difficult.

I am terminating the mutex in the following way

Code:
/* If critical section is being accessed, 
get current thread to leave it*/

if(lock_flag == 1)
  pthread_mutex_unlock( &cs_mutex);

if( (ret = pthread_mutex_destroy(&cs_mutex)) != 0)
{
    printf("\nError occurred in terminating mutex");
    exit(1);
}

Is this an appropriate way of terminating the mutex ? If not could someone please advise a much better strategy ?

cheers
 
All times are GMT -4. The time now is 08:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy