Pthread_mutex_destroy Error 16
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About pthread_mutex_destroy example Us Learn more about Stack Overflow the company Business Learn more about hiring
Pthread_mutex_destroy Ebusy
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the pthread_mutex_destroy necessary Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to handle error conditions of pthread mutex example pthread_mutex_destroy up vote 1 down vote favorite When I try to destroy mutex via pthread_mutex_destroy(&mutex), it intermittently fails. I am doing an assert if the pthread_mutex_destroy fails. But do we have a better option compared to assert (apart from raising exception)? EDIT: void cleanUp() { int rval=0; rval = pthread_cond_destroy(&m_Condition); assert(rval == 0); rval = pthread_mutex_destroy(&m_Mutex); assert(rval == 0); rval = pthread_mutexattr_destroy(&m_Attr); assert(rval == 0); } EDIT
Pthread_cond_destroy
2: void semaphoreVMware::semaphoreVMware() { int rval = 0; rval = pthread_mutexattr_init(&m_Attr); assert(rval == 0); rval = pthread_mutexattr_settype(&m_Attr, PTHREAD_MUTEX_RECURSIVE); assert(rval == 0); rval = pthread_mutex_init(&m_Mutex, &m_Attr); assert(rval == 0); rval = pthread_cond_init(&m_Condition, NULL); assert(rval == 0); } EDIT 3:Declaration of the mutex: env::Mutex m_Mutex; c unix pthreads mutex share|improve this question edited Dec 10 '13 at 13:49 alk 45.1k53497 asked Dec 10 '13 at 6:34 Ravikanth 357 do you know why it is failing? –Glenn Teitelbaum Dec 10 '13 at 6:36 Can you please post some sample code? Can't you check the return value and take an action instead of throwing an assert? –ServerMonkey Dec 10 '13 at 6:37 @ServerMonkey almost all of the errors from pthread_mutex_destroy are programming errors, with the exception of resource limitation, which should not be intermittent. It would be better to fix the problems so that the errors do not occur. –Glenn Teitelbaum Dec 10 '13 at 6:41 Hello,Thanks for your reply.Actually the cleanup code which i have posted gets called whenever we stop our service.The scenario is starting and stopping of the service and this we doing in a loop.When we do these iteration,pthread_mutex_dest
destroy and initialize a mutex SYNOPSIS [THR] #include <pthread.h>
int pthread_mutex_t mutex pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_init(pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr);
pthread_mutex_t mutex =
Pthread_mutex_t Struct
PTHREAD_MUTEX_INITIALIZER; DESCRIPTION The pthread_mutex_destroy() function shall destroy the mutex object referenced by mutex; the mutex object http://stackoverflow.com/questions/20487752/how-to-handle-error-conditions-of-pthread-mutex-destroy becomes, in effect, uninitialized. An implementation may cause pthread_mutex_destroy() to set the object referenced by mutex to an invalid value. A destroyed mutex object can be reinitialized using pthread_mutex_init(); the results of otherwise referencing the object after it has been destroyed are undefined. It shall http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_destroy.html be safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex results in undefined behavior. The pthread_mutex_init() function shall initialize the mutex referenced by mutex with attributes specified by attr. If attr is NULL, the default mutex attributes are used; the effect shall be the same as passing the address of a default mutex attributes object. Upon successful initialization, the state of the mutex becomes initialized and unlocked. Only mutex itself may be used for performing synchronization. The result of referring to copies of mutex in calls to pthread_mutex_lock(), pthread_mutex_trylock(), pthread_mutex_unlock(), and pthread_mutex_destroy() is undefined. Attempting to initialize an already initialized mutex results in undefined behavior. In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are statically allocated.
text] pthread_mutex_destroy returns EBUSY, but the mutex isn't locked From: "Adrian Ludwin"
23 فروردین 1392, 00:07 قبل از ظهرI have written a simple example on pthread_mutexattr_setprotocol. I have two problems; Although I added #define _GNU_SOURCE at top of my source code, the program did not compile in c because it could not able to identify protocol's attribute like >PTHREAD_PRIO_INHERIT and ...,in this case I had to convert it in C++ but know there is another problem. I can not destroy mutex. the number of error is 16 that means is being >used by another mutex but I do not which one? I tried even to unlock the mutex before to >destroy it but there was another error (22) which means that this mutex did not lock it. >can somebody tell me what should I do? I wrote my sample in eclips on ubuntu/linaro 4.6.3 Thank yoU //#define _GNU_SOURCE #include