pthread_mutex_lock gives assertion. pthread_mutex_init returns 95. - Unix
This is a discussion on pthread_mutex_lock gives assertion. pthread_mutex_init returns 95. - Unix ; Hi,
Yesterday, I compiled a small mutex program on a Debian lenny AMD64
using GCC 4.2.x. The compilation went through successfully, but
running the application caused errors randomly.
Sometimes, the application aborted with the following:
tst_app: pthread_mutex_lock.c:87: __pthread_mutex_lock: Assertion
`mutex->__data.__owner ...
-
pthread_mutex_lock gives assertion. pthread_mutex_init returns 95.
Hi,
Yesterday, I compiled a small mutex program on a Debian lenny AMD64
using GCC 4.2.x. The compilation went through successfully, but
running the application caused errors randomly.
Sometimes, the application aborted with the following:
tst_app: pthread_mutex_lock.c:87: __pthread_mutex_lock: Assertion
`mutex->__data.__owner == 0' failed.
Aborted
Sometimes, the function pthread_mutex_init(...) returned an error code
95, which is not a possible return code based on the manual page (man
3 pthread_mutex_init).
Both errors didn't not happen when compiled on a Debian etch Intel
using GCC 4.1.2.
Can anyone help me on this? Thanks in advance.
Regards,
wenlong (boon leong)
The test application source code:
#include
#include
int main()
{
pthread_mutex_t m_;
pthread_mutexattr_t ptype;
int rc = pthread_mutexattr_settype(&ptype,
PTHREAD_MUTEX_RECURSIVE);
if (rc != 0)
{
printf("pthread_mutexattr_settype failed. rc=%d \n", rc);
return 1;
}
rc = pthread_mutex_init(&m_, &ptype); // rc=95 randomly.
if (rc != 0)
{
printf("pthread_mutex_init failed. rc=%d \n", rc);
return 1;
}
rc = pthread_mutex_lock(&m_); // Aborts here randomly.
if (0 == rc)
{
printf("lock: ok \n");
}
else
{
printf("lock failed. rc=%d \n", rc);
}
rc = pthread_mutex_unlock(&m_);
if (0 != rc)
{
printf("unlock failed. rc=%d \n", rc);
}
rc = pthread_mutex_destroy(&m_);
if (rc != 0)
{
printf("Fail to destroy a mutex. rc=%d \n", rc);
return 1;
}
return 0;
}
-
Re: pthread_mutex_lock gives assertion. pthread_mutex_init returns95.
wenlong writes:
> pthread_mutexattr_t ptype;
> int rc = pthread_mutexattr_settype(&ptype, PTHREAD_MUTEX_RECURSIVE);
You must initialize it with pthread_mutexattr_init().
Don't forget to also pthread_mutexattr_destroy() it later.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
-
Re: pthread_mutex_lock gives assertion. pthread_mutex_init returns95.
On Jun 6, 12:51 pm, Paul Pluzhnikov wrote:
> You must initialize it with pthread_mutexattr_init().
> Don't forget to also pthread_mutexattr_destroy() it later.
Thanks Paul, I'll try that. 