Pthread Mutex Destroy Error Code
Contents |
destroy and initialize a mutex SYNOPSIS [THR] #include <pthread.h>
int pthread_mutex_destroy(pthread_mutex_t *mutex);
Pthread_mutex_destroy Example
int pthread_mutex_init(pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr);
pthread_mutex_t mutex pthread mutex example = PTHREAD_MUTEX_INITIALIZER; DESCRIPTION The pthread_mutex_destroy() function shall destroy the mutex object
Pthread Cond Destroy
referenced by mutex; the mutex object becomes, in effect, uninitialized. An implementation may cause pthread_mutex_destroy() to set the object referenced by mutex to an invalid value. A pthread_mutex_destroy ebusy 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 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 pthread_mutex_t mutex 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. The effect shall be equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed. RETURN VALUE If successful, the pthread_mutex_destroy() and pthread_mutex_init() functions shall return zero; otherwise, an error number shall be returned to indicate the error. The [EBUSY] and [EINVAL] error checks, if implemented, act as if they were perfor
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Pthread_mutex_destroy Error 16
workings and policies of this site About Us Learn more about Stack pthread_mutex_destroy return value Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Pthread Mutex Attributes
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_destroy.html them; it only takes a minute: Sign up How to handle error conditions of 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 http://stackoverflow.com/questions/20487752/how-to-handle-error-conditions-of-pthread-mutex-destroy 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 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
Login: [x] Format For Printing -XML -Clone This Bug -Last Comment First Last Prev Next This bug is not in your last search results. Bug113588 - NPTL pthread_mutex_destroy return EBUSY even if mutex is not locked... Summary: NPTL pthread_mutex_destroy return EBUSY even if mutex is not locked... Status: CLOSED NOTABUG Aliases: None Product: Red Hat Enterprise Linux 3 Classification: Red Hat Component: kernel (Show other bugs) Sub Component: --- Version: 3.0 Hardware: All Linux Priority medium Severity medium TargetMilestone: --- TargetRelease: --- Assigned To: Arjan van de Ven QA Contact: Brian Brock Docs Contact: URL: Whiteboard: Keywords: Depends On: Blocks: Show dependency tree /graph Reported: 2004-01-15 11:39 EST by Umesh R. Patil Modified: 2007-11-30 17:07 EST (History) CC List: 5 users (show) drepper.fsp petrides riel roland upatil See Also: Fixed In Version: Doc Type: Bug Fix Doc Text: Story Points: --- Clone Of: Environment: Last Closed: 2004-01-15 12:55:37 EST Type: --- Regression: --- Mount Type: --- Documentation: --- CRM: Verified Versions: Category: --- oVirt Team: --- RHEL 7.3 requirements from Atomic Host: Cloudforms Team: --- Attachments (Terms of Use) Add an attachment (proposed patch, testcase, etc.) Groups: None (edit) Description Umesh R. Patil 2004-01-15 11:39:08 EST From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030922 Description of problem: pthread_mutex_destroy should return EBUSY if the mutex being destroyed is currently locked. If ptread_mutex_unlock is called without calling pthread_mutex_lock, pthread_mutex_destroy in NPTL returns EBUSY. This scenario can happen in cleanup handlers where a mutex is being unlocked when a thread exits. Version-Release number of selected component (if applicable): glibc-2.3.2-95.6, kernel-2.4.21-4.EL, RHE ES 3.0, gcc-3.2.3-20 How reproducible: Always Steps to Reproduce: 1. prog.c: #include