Bug 2746 - mutex with ERRORCHECK attribute fails to unlock on child after fork
Summary: mutex with ERRORCHECK attribute fails to unlock on child after fork
Status: RESOLVED DUPLICATE of bug 2745
Alias: None
Product: glibc
Classification: Unclassified
Component: nptl (show other bugs)
Version: 2.3.6
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-09 19:26 UTC by Rafal Dabrowa
Modified: 2014-07-04 22:12 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafal Dabrowa 2006-06-09 19:26:07 UTC
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.
Comment 1 Ulrich Drepper 2006-06-10 07:02:44 UTC

*** This bug has been marked as a duplicate of 2745 ***