Pthread Mutex Lock Error
Contents |
- lock and unlock a mutex SYNOPSIS [THR] #include <pthread.h>
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t pthread_mutex_lock example *mutex); DESCRIPTION The mutex object referenced pthread_mutex_lock return value by mutex shall be locked by calling pthread_mutex_lock(). If the mutex is already locked, the calling thread shall block
What Is Pthread_mutex_lock
until the mutex becomes available. This operation shall return with the mutex object referenced by mutex in the locked state with the calling thread as its owner. [XSI] If the
Pthread_mutex_lock Error 22
mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall not be provided. Attempting to relock the mutex causes deadlock. If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, undefined behavior results. If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking shall be provided. If a thread attempts to relock a mutex that it man pthread_mutex_lock has already locked, an error shall be returned. If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, an error shall be returned. If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex shall maintain the concept of a lock count. When a thread successfully acquires a mutex for the first time, the lock count shall be set to one. Every time a thread relocks this mutex, the lock count shall be incremented by one. Each time the thread unlocks the mutex, the lock count shall be decremented by one. When the lock count reaches zero, the mutex shall become available for other threads to acquire. If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, an error shall be returned. If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in undefined behavior. Attempting to unlock the mutex if it was not locked by the calling thread results in undefined behavior. Attempting to unlock the mutex if it is not lo
and unlock a mutex SYNOPSIS #include <pthread.h>
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
DESCRIPTION The mutex object referenced by mutex shall be locked by a call to pthread_mutex_lock() that returns zero or
Pthread_mutex_unlock
[EOWNERDEAD]. If the mutex is already locked by another thread, the calling thread shall pthread_mutex_init block until the mutex becomes available. This operation shall return with the mutex object referenced by mutex in the locked state pthread_mutex_lock timeout with the calling thread as its owner. If a thread attempts to relock a mutex that it has already locked, pthread_mutex_lock() shall behave as described in the Relock column of the following table. If a http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_lock.html thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, pthread_mutex_unlock() shall behave as described in the Unlock When Not Owner column of the following table. Mutex Type Robustness Relock Unlock When Not Owner NORMAL non-robust deadlock undefined behavior NORMAL robust deadlock error returned ERRORCHECK either error returned error returned RECURSIVE either recursive error returned (see below) DEFAULT non-robust http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html undefined undefined behavior behavior DEFAULT robust undefined error returned behavior If the mutex type is PTHREAD_MUTEX_DEFAULT, the behavior of pthread_mutex_lock() may correspond to one of the three other standard mutex types as described in the table above. If it does not correspond to one of those three, the behavior is undefined for the cases marked . Where the table indicates recursive behavior, the mutex shall maintain the concept of a lock count. When a thread successfully acquires a mutex for the first time, the lock count shall be set to one. Every time a thread relocks this mutex, the lock count shall be incremented by one. Each time the thread unlocks the mutex, the lock count shall be decremented by one. When the lock count reaches zero, the mutex shall become available for other threads to acquire. The pthread_mutex_trylock() function shall be equivalent to pthread_mutex_lock(), except that if the mutex object referenced by mutex is currently locked (by any thread, including the current thread), the call shall return immediately. If the mutex type is PTHREAD_MUTEX_RECURSIVE and the mutex is currently owned by the calling thread, the mutex lock count shall be incremented by one and the pthread_mutex_trylock() function shall immediately retu
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 Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads http://stackoverflow.com/questions/12781944/pthread-mutex-lock-returns-invalid-argument with us Stack Overflow Questions Jobs 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 them; it only takes a minute: https://www.sourceware.org/pthreads-win32/manual/pthread_mutex_init.html Sign up pthread_mutex_lock returns invalid argument up vote 4 down vote favorite I am working on some C code and am having a problem with locking a mutex. The code does a call to a function and this function locks a lock error mutex to ensure a file pointer doesn't get overwritten, this works fine for several instances, probably about 10-20 separate calls of the function being called, but on the next call, pthread_mutex_lock will return with a result of 22. I've then put this result into strerror(); and got back invalid argument. What does invalid argument means, thanks for any help you can provide. c debugging pthreads mutex share|improve this question edited Oct 8 '12 at 12:43 vy32 9,0311661128 asked Oct 8 '12 at 12:39 pthread mutex lock Boardy 9,90554168284 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted Sounds like you have a threading problem or a wild point somewhere else in your program. Try printing the value of the mutex pointer. Try having another thread that simply locks the mutex and then prints to a log file the time and that the lock was successful, then unlocks the mutex. I suspect the problem is not where you are looking. Also, as other have said here, your best bet is to create a very small test program that demonstrates the problem and post it here. Chances are you won't be able to get that small program to demonstrate the error. Then slowly add all of your original code into the small program until the error returns. If it returns, you now know what caused the problem. If it doesn't return, you're done. share|improve this answer answered Oct 8 '12 at 12:43 vy32 9,0311661128 add a comment| up vote 7 down vote 22 is ENVAL error code which means invlalid argument. Make sure that you have initilized you mutex, or if at some point you have unitilized it somewhere. Also man pthread_mutex_lock says: EINVAL The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling. I don't quite understand this but it probably means that you need to change thread's priority. I am not sure
- operations on mutexes Synopsis #include