Home > pthread mutex destroy error > pthread_mutex_destroy error 16

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] pthread_mutex_init #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; [Option End] 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" To: libc-help at sourceware dot org https://sourceware.org/ml/libc-help/2008-06/msg00013.html Date: Wed, 4 Jun 2008 08:48:16 -0400 Subject: pthread_mutex_destroy returns http://barnamenevis.org/archive/index.php/t-392891.html EBUSY, but the mutex isn't locked Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :to:subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=T5wkrt6+RoThUCttzjjg4jMqf2yQA03k0EVidLUh6T0=; b=qETnV7i1saljKba0TqwlunE6ce68XuOW6DuxjrWEWRUg0Y8eH2My+0oymcT+VNStZK mcV+QuGvUVSMPDUsSSp1+Qbx0kHB2czKV1wBL0h/sU+A2+sJxpCP/ulTZk82+Deu+q1f eMATbU5l97gXtOmNQut4TEznfDZ2GqP2uN71U= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=plWdiL/Zee8Q9aFec3ZzhOxxueDWrS4hSVA0GSbT7LiGhPB60LyDRDmcsQmoDdY1hw pY8N6eaiDAfG1LnVqoISg5KG9ylXoq1SKYogz2fe1YXGknWaekzNjtZ7x8x9wda16afR kSQadHFc5BPwp7JjI9tsUiv3eRVPO2bYF9EzQ= Reply-to: adrian dot ludwin at gmail dot com Hi all, I've pthread_mutex_destroy error got a problem with a mutex that's been bugging me for a while. On a very specific platform (an Opteron running CentOS with kernel 2.6.9-55.ELsmp with glibc version 2.3.4-2.36) I have less than 1% of my pthread_mutex_destroy calls fail with the error "EBUSY." The errors are not repeatable reliably on the pthread_mutex_destroy error 16 same machine, and not repeatable at all on another platform (a Core 2 Duo running the same OS but with glibc version 2.3.4-2.25). I have not been able to recreate the error in a simple testcase. In the real program, the error affects about four mutexes in completely separate parts of the program. I am certain the mutex is not actually locked, since I've started printing out its contents prior to destroying them. One example is as follows: Mutex 0x920df0: lock=0, count=0, owner=0, nusers=2, kind=2 (The "kind=2" field means this is an error checking mutex, but the problem occurs for normal mutexes as well; this ensures that I'm not unlocking a mutex I don't own). As you can see, the futex ("lock") is zero, as is both the count and owning thread. Only nusers is non-zero; by far the most common value I see is 1, though I've also seen

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 #include #include "check.h" int ShowProtocol(pthread_mutexattr_t *mta) { int rc; int protocol; printf("Check Protocol attribute\n"); rc = pthread_mutexattr_getprotocol(mta, &protocol); checkResults("pthread_mutexattr_getprotocol()\n", rc); printf ("%d\n" ,protocol); printf("The Protocol attributed is: "); switch (protocol) { case PTHREAD_PRIO_INHERIT: printf("PTHREAD_PRIO_INHERIT\n"); break; case PTHREAD_PRIO_NONE: printf("PTHREAD_PRIO_NONE\n"); break; case PTHREAD_PRIO_PROTECT : printf("PTHREAD_PRIO_PROTECT\n"); break; default : printf("! protocol Error Protocol=%d !\n", protocol); exit(1); } return protocol; } int main(int argc, char **argv) { int rc=0; pthread_mutexattr_t mta; pthread_mutex_t mutex; printf("Enter Testcase - %s\n", argv[0]); printf("Create a default mutex attribute\n"); rc = pthread_mutexattr_init(&mta); checkResults("pthread_mutexattr_init()\n", rc); ShowProtocol(&mta); printf("Change mutex Protocol attribute to PTHREAD_PRIO_PROTECT\n"); rc = pthread_mutexattr_setprotocol(&mta, PTHREAD_PRIO_PROTECT); checkResults("pthread_mutexattr_setProtocol()\n", rc); ShowProtocol(&mta); printf("Cleanup\n"); rc = pthread_mutex_destroy(&mutex); checkResults("pthread_mutex_destroy()\n", rc); rc = pthread_mutexattr_destroy(&mta); checkResults("pthread_mutexattr_destroy()\n", rc); printf("Main completed\n"); return 0; } #ifndef CHECK_H_ #define CHECK_H_ /* headers used by a majority of the example program */ #include #include #include #include /* Simple function to check the return code and exit the program if the function call failed */ static void checkResults(char *string, int rc) { if (rc) { printf("Error on : %s, rc=%d", string, rc); exit(EXIT_FAILURE); } return; } #endif /* CHECK_H_ */ FastCodeجمعه 23 فروردین 1392, 00:30 قبل از ظهرFirst I

 

Related content

pthread_mutex_destroy error

Pthread mutex destroy Error table id toc tbody tr td div id toctitle Contents div ul li a href Pthread mutex destroy Ebusy a li li a href Pthread cond destroy a li li a href Pthread mutex init Example In C a li ul td tr tbody table p destroy and relatedl initialize a mutex SYNOPSIS tt sup a href javascript open code 'THR' THR a sup pthread mutex destroy example img src images opt-start gif alt Option Start border include a p h id Pthread mutex destroy Ebusy p href basedefs pthread h html pthread h a br

pthread_mutex_destroy error codes

Pthread mutex destroy Error Codes table id toc tbody tr td div id toctitle Contents div ul li a href Pthread mutex destroy Example a li li a href Pthread mutex destroy Error a li li a href Pthread mutex initializer Vs Pthread mutex init a li li a href Pthread mutex t Mutex a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you relatedl might have Meta Discuss the workings and policies of p h id Pthread mutex destroy Example p this site About Us

pthread_mutex_destroy error code 16

Pthread mutex destroy Error Code table id toc tbody tr td div id toctitle Contents div ul li a href Pthread cond destroy a li li a href Pthread Mutex Example a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings relatedl and policies of this site About Us Learn more about pthread mutex destroy example Stack Overflow the company Business Learn more about hiring developers or posting ads with pthread mutex destroy ebusy us Stack Overflow Questions Jobs Documentation