This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/2745] New: mutex with ERRORCHECK attribute fails to unlock on child after fork


pthread_mutex_unlock function unexpectedly fails when called in child process 
on a mutex, which:
 * has PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_RECURSIVE attribute
 * has been locked in parent process

Possibility of unlocking of a mutex locked in parent process is typically used 
in handlers installed by pthread_atfork routine and is supposed to work.

Code example:

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    pthread_mutex_t mutex;
    pthread_mutexattr_t attr;
    pid_t pid;
    int err;

    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    pthread_mutex_init(&mutex, &attr);
    pthread_mutex_lock(&mutex);
    pid = fork();
    err = pthread_mutex_unlock(&mutex);
    printf("pid=%d, err=%d\n", pid, err);
    return 0;
}

---------------------------------------------------
Output:
    pid=0, err=1
    pid=5817, err=0
err should be 0 both on child and on parent.

-- 
           Summary: mutex with ERRORCHECK attribute fails to unlock on child
                    after fork
           Product: glibc
           Version: 2.3.6
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: rdabrowa at poczta dot onet dot pl
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=2745

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]