Pthread Mutex Lock Error 22
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_lock(&mutex)failed with error 22 Us Learn more about Stack Overflow the company Business Learn more about hiring
Mutex Lock Failed
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join pthread mutex example 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: Sign up pthread_mutex_lock returns 22 in C pthread_mutex_initializer [duplicate] up vote 1 down vote favorite This question already has an answer here: pthread_mutex_lock returns invalid argument 2 answers I'm learning how to use Pthread in C. I've tried to use pthread_mutex_lock. It is supposed to return 0 when the locking is successful. But my program always returns 22 - invalid argument. The code is as follow: pthread_mutex_lock is used in work_function #include
Pthread_mutex_unlock
- 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 *mutex); DESCRIPTION The mutex object referenced by mutex shall pthread_mutex_destroy be locked by calling pthread_mutex_lock(). If the mutex is already locked, the calling thread shall block until the mutex
Std::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 mutex type is PTHREAD_MUTEX_NORMAL, deadlock http://stackoverflow.com/questions/30511046/pthread-mutex-lock-returns-22-in-c 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 has already locked, an error shall be http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_lock.html 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 locked results in undefined behavior. The pthread_mutex_trylock() function shall be equivalent to pthread_mutex_lock(), except
Forum Visual C++ & C++ Programming C++ (Non Visual C++ Issues) pthread_mutex_lock fails If this is your first visit, be sure to check out the FAQ by clicking the http://forums.codeguru.com/showthread.php?508898-pthread_mutex_lock-fails link above. You may have to register or Login before you can post: click https://groups.google.com/d/topic/googlemock/o0spo6ZR08A the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 6 of 6 Thread: pthread_mutex_lock fails Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode pthread mutex February 18th, 2011,12:40 AM #1 srinivasant View Profile View Forum Posts Junior Member Join Date Jul 2007 Posts 15 pthread_mutex_lock fails Hi, I have linked statically libodbc++ (libodbc++-mt.a) with my CPP application and connect to MySQL from various threads simultaneously from my application. At some point my application crashes with the following error, terminate called after throwing an instance of 'odbc::SQLException' what(): [libodbc++]: OS error, mutex lock failed HY000 pthread mutex lock : [libodbc++]: OS error, mutex lock failed :: [Open DB] : IN DB /home/test/Users/Srini/xxxxxxx/dbnamexxx terminate called recursively HY000 : [libodbc++]: OS error, mutex lock failed :: [Open DB] : IN DB /home/test/Users/Srini/xxxxxxx/dbnamexxx terminate called recursively HY000 : [libodbc++]: OS error, mutex lock failed :: [Open DB] : IN DB /home/test/Users/Srini/xxxxxxx/dbnamexxx Aborted Seems the pthread_mutex_lock() in src/threads.cpp fails with error and libodbc throws exception and hence application crashes (running in my application in debug mode). I have checked the return value of pthread_mutex_lock() and it is EINVAL (22) which means Invalid Argument. The details of my setup is as follows, OS : Cent OS 5.3 libodbc++ : v0.2.3 unixODBC : v2.2.15pre MySQL Driver : v3.51.27 MySQL Server : v5.1.39 My odbcinst.ini file is as follows, -------------------8<---------------------- [ODBC] Trace = No Trace File = /tmp/sql.log Pooling = Yes [MySQL] Description = Driver = /usr/local/lib/libmyodbc3-3.51.27.so Driver64 = Setup = /usr/local/lib/libmyodbc3S-3.51.27.so Setup64 = UsageCount =1 CPTimeout =300 CPReuse =1 Threading =0 ------------------->8---------------------- My configure option for libodbc++ is as follows, ./configure --enable-static=yes --with-odbc=/home/path/to/unixodbc/unixODBC-2.2.15pre/DriverManager/.libs/ --enable-threads=yes I have also tested with libodbc++ v0.2.5 and still I face the same issue. Has anyone experienced similar problem. Any help would be greatly appreciated. Regards, Srinivasan Reply With Quote February 18th, 2011,06:14 AM #
von GoogleAnmeldenAusgeblendete FelderNach Gruppen oder Nachrichten suchen