Home > pthread mutex lock return > pthread_mutex_lock error code 35

Pthread_mutex_lock Error Code 35

SyntaxNext: Unlocking a Mutex pthread_mutex_lock Return Values pthread_mutex_lock() returns zero after completing successfully. Any other return value indicates that an error occurred. When any pthread_mutex_lock example of the following conditions occurs, the function fails and returns the

Pthread_mutex_lock Return Value

corresponding value. EAGAIN Description: The mutex could not be acquired because the maximum number of

Pthread_mutex_lock Return Value 22

recursive locks for mutex has been exceeded. EDEADLK Description: The current thread already owns the mutex. If the mutex was initialized with the PTHREAD_MUTEX_ROBUST_NProbustness attribute, pthread_mutex_lock()

Man Pthread_mutex_lock

may return one of the following values: EOWNERDEAD Description: The last owner of this mutex terminated while holding the mutex. This mutex is now owned by the caller. The caller must attempt to make the state protected by the mutex consistent. If the caller is able to make the state consistent, call pthread_mutex_consistent_np() pthread_mutex_trylock for the mutex and unlock the mutex. Subsequent calls to pthread_mutex_lock() behave normally. If the caller is unable to make the state consistent, do not call pthread_mutex_init() for the mutex. Unlock the mutex instead. Subsequent calls to pthread_mutex_lock() fail to acquire the mutex and return an ENOTRECOVERABLE error code. If the owner that acquired the lock with EOWNERDEAD terminates while holding the mutex, the next owner acquires the lock with EOWNERDEAD. ENOTRECOVERABLE Description: The mutex you are trying to acquire was protecting state left irrecoverable by the mutex's previous owner. The mutex has not been acquired. This irrecoverable condition can occur when: The lock was previously acquired with EOWNERDEAD The owner was unable to cleanup the state The owner unlocked the mutex without making the mutex state consistent ENOMEM Description: The limit on the number of simultaneously held mutexes has been exceeded. Previous: pthread_mutex_lock SyntaxNext: Unlocking a Mutex © 2010, Oracle Corporation and/or its affiliates

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 pthread_mutex_recursive_np ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join pthread mutex lock 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 pthread_mutex_initializer minute: 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 http://docs.oracle.com/cd/E19253-01/816-5137/sync-238/index.html a 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 http://stackoverflow.com/questions/12781944/pthread-mutex-lock-returns-invalid-argument at 12:39 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 priorit

the interface may not be implemented on Linux. Name pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock - lock and unlock a mutex Synopsis #include https://linux.die.net/man/3/pthread_mutex_lock int pthread_mutex_lock(pthread_mutex_t *mutex); int pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_mutex_unlock(pthread_mutex_t *mutex); https://forum.juce.com/t/pthread-mutex-lock-full-assertion/7735 Description The mutex object referenced by mutex shall be locked by calling pthread_mutex_lock(). If the mutex is already locked, the calling thread shall block until the mutex becomes available. This operation shall return with the mutex object referenced by mutex in the locked state pthread_mutex_lock return with the calling thread as its owner. If the 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 pthread_mutex_lock return value error checking shall be provided. If a thread attempts to relock a mutex that it 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 recursi

a _pthreadmutex_lock_full assertion failure in pthread_mutex_lock.c (line 309) - '(-(e)) != 35 || (kind != PTHREAD_MUTEX_ERRORCHECK_NP && kind != PTHREAD_MUTEX_RECURSIVE_NP)'. As I said, this code works fine in Windows. Any ideas why the ScopedLock would act differently in Linux? Thanks! ****Note: Using latest version of Ubuntu.**** Here is the code in Linux where the assertion fails... if (INTERNAL_SYSCALL_ERROR_P (e, __err) && (INTERNAL_SYSCALL_ERRNO (e, __err) == ESRCH || INTERNAL_SYSCALL_ERRNO (e, __err) == EDEADLK)) { assert (INTERNAL_SYSCALL_ERRNO (e, __err) != EDEADLK || (kind != PTHREAD_MUTEX_ERRORCHECK_NP && kind != PTHREAD_MUTEX_RECURSIVE_NP)); /* ESRCH can happen only for non-robust PI mutexes where the owner of the lock died. */ assert (INTERNAL_SYSCALL_ERRNO (e, __err) != ESRCH || !robust); /* Delay the thread indefinitely. */ while (1) pause_not_cancel (); } jules 2011-11-18 18:50:42 UTC #2 Never seen that one before.. Can you give me some code that I could use to reproduce it? jhewell 2011-11-18 19:22:18 UTC #3 I'll see what I can put together. It's part of a very large project with many pieces working together and interacting with hardware over firewire. Let me see if I can reproduce it on a smaller scale example. By the way, do you know what the maximum of locks in a PTHREAD_MUTEX_RECURSIVE lock is - I keep seeing documentation that says there is a maximum but have never seen that value. Thanks. jules 2011-11-18 20:52:21 UTC #4 Is there a maximum? I would have thought it just contained a counter for the recursion depth, rather than having a finite number of slots. jhewell 2011-11-18 21:03:36 UTC #5 That's what I thought, but I found the statement below here - http://pubs.opengroup.org/onlinepubs/007904875/functions/pthread_mutex_lock.html [EAGAIN] [XSI] The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded. The func


Related content

No related pages.