Bug 204863 - pthread_mutex_init fails when given a mutexattr
pthread_mutex_init fails when given a mutexattr
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
5
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-08-31 19:08 EDT by David Moore
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-09-01 02:43:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description David Moore 2006-08-31 19:08:42 EDT
pthread_mutex_init fails sometimes with errno=95 Operation not supported
when given a mutexattr

The following code snippet shows this problem...
int main()
{
    pthread_mutex_t pthreadMutex;
    pthread_mutexattr_t mutexattr;
    int status;
    status = pthread_mutexattr_settype (&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
    if (status)
    {
        printf("1 %d %s\n", status, strerror(status));
    }
    status = pthread_mutex_init(&pthreadMutex, &mutexattr);
    if (status)
    {
        printf("2 %d %s\n", status, strerror(status));
    }


    return 0;
}
Compiled with  g++ -g -lpthread mutex.cpp -o mutex

Results in 2 95 Operation not supported

The same thing also happens for attributes PTHREAD_MUTEX_RECURSIVE,
PTHREAD_MUTEX_RECURSIVE_NP.

Curiously about 1 time in 10 times the call will succeed.

And if the variables are dynamically allocated it seems to work.  I.e. this code...
int main()
{
    pthread_mutex_t* pPthreadMutex = new pthread_mutex_t;
    pthread_mutexattr_t* pMutexattr = new pthread_mutexattr_t;
    int status;
    status = pthread_mutexattr_settype (pMutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
    if (status)
    {
        printf("1 %d %s\n", status, strerror(status));
    }
    status = pthread_mutex_init(pPthreadMutex, pMutexattr);
    if (status)
    {
        printf("2 %d %s\n", status, strerror(status));
    }


    return 0;
}

Results in no err.

Version-Release number of selected component (if applicable):
glibc-2.4-8
libpthread-2.4.so
gcc (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)

This is a 64bit dual core AMD machine.  I will try and test on another machine.

Please let me know if there's any other info I can give to help pin this problem
down.

Thanks!
Comment 1 David Moore 2006-08-31 19:29:16 EDT
With an AMD athelon 64 running FC5 x86 (*not* x86_64) the sample code runs fine.
Comment 2 Jakub Jelinek 2006-09-01 02:43:04 EDT
Why are you surprised when mutexattr is unitialized?
The code must use pthread_mutexattr_init first.

Note You need to log in before you can comment on or make changes to this bug.