[boost::mutex] Suspicious EINVAL error

Hello users. I am running a single thread which locks and unlocks mutexes, and I get the following error: * /usr/include/boost/thread/pthread/mutex.hpp:55: void boost::mutex::lock(): Assertion `!pthread_mutex_lock(&m)' failed, *after a boost::shared_mutex::lock() or a boost::shared_mutex::try_lock(). In fact, I checked the error code that pthread_mutex_lock(&m) returned and it was the EINVAL error (code number 22). The posix manual gives 2 possibilities for this error: 1) the mutex has not been properly initialized, or 2) 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. Sadly, the mutex is correctly initialized. As far as possibility (2) is concerned, well I cannot interpret it... My code is pretty big, so I cannot provide a complete snippet, but roughly (just in case it helps): **************************************************************************************************** I have the following class: class Vertex { boost::shared_mutex mtx; Vertex() {} }; whose objects call Vertex::mtx->lock(), Vertex::mtx->unlock(), Vertex::mtx->lock_shared(), and Vertex::mtx->unlock_shared(). The above error is produced whenever a specific object (residing in memory) locks or even try_locks its mutex. It always happens for a specific object. **************************************************************************************************** I am using the GNU C++ compiler 4.4.3 on Ubuntu x86_64. I do realize that the information I provide in this email is little, but I, being new in boost::mutexes and having spent so much time on it, decided to give it a shot. Best Regards, Panagiotis Foteinos

Message du 02/04/11 01:59 De : "Panagiotis Foteinos"
A : boost-users@lists.boost.org Copie à : Objet : [Boost-users] [boost::mutex] Suspicious EINVAL error
Hello users.
I am running a single thread which locks and unlocks mutexes, and I get the following error: *
/usr/include/boost/thread/pthread/mutex.hpp:55: void boost::mutex::lock(): Assertion `!pthread_mutex_lock(&m)' failed,
*after a boost::shared_mutex::lock() or a boost::shared_mutex::try_lock().
I do realize that the information I provide in this email is little, but I, being new in boost::mutexes and having spent so much time on it, decided to give it a shot.
Hi, this kind of error is quite common. It seems that you try to lock the mtx twice. Could you show the error when you have a try_lock? Do you use the RAII locks that ensure that lock/unlock are pairwise? Best, Vicente

Thank you Vicente for your reply.
If that was the case, however, then the error code would be EDEADLK and not
EINVAL.
Anyhow,
I was able to solve my problem 15 mins ago. It was an initialization error:
objects that had been freed were trying to access their mutex...
Sorry to bother you people.
Regards,
Panagiotis Foteinos
On Sun, Apr 3, 2011 at 4:26 PM, Vicente BOTET
Message du 02/04/11 01:59 De : "Panagiotis Foteinos"
A : boost-users@lists.boost.org Copie à : Objet : [Boost-users] [boost::mutex] Suspicious EINVAL error
Hello users.
I am running a single thread which locks and unlocks mutexes, and I get the following error: *
/usr/include/boost/thread/pthread/mutex.hpp:55: void boost::mutex::lock(): Assertion `!pthread_mutex_lock(&m)' failed,
*after a boost::shared_mutex::lock() or a boost::shared_mutex::try_lock().
I do realize that the information I provide in this email is little, but I, being new in boost::mutexes and having spent so much time on it, decided to give it a shot.
Hi,
this kind of error is quite common. It seems that you try to lock the mtx twice. Could you show the error when you have a try_lock? Do you use the RAII locks that ensure that lock/unlock are pairwise?
Best, Vicente _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Panagiotis Foteinos
-
Vicente BOTET