This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports 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]

Process-shared robust mutexes broken on MIPS.


I'm running the following program on glibc+ports 2.5, kernel 2.6.17.7. 

It runs on i686 but locks up on MIPS.

A process-shared robust mutex, and process-shared condition variable are
created. Then two processes share these objects. The waiter keeps
locking the mutex, waiting on the condition and unlocking the mutex.
The signaler just keeps locking the mutex, signaling the condition and
unlocking.

Eventually a deadlock situation occurs (on MIPS only).

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <sys/mman.h>

typedef struct {
    pthread_mutex_t mutex;
    pthread_cond_t cond;
} lock_t;

int
main(int argc, char *argv[])
{
    pthread_mutexattr_t mutex_attr;
    pthread_condattr_t cond_attr;
    lock_t *lock = 0;
    pid_t pid;

    pthread_mutexattr_init(&mutex_attr);
    pthread_mutexattr_setrobust_np(&mutex_attr,
PTHREAD_MUTEX_ROBUST_NP);
    pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED);

    pthread_condattr_init(&cond_attr);
    pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);

    lock = (lock_t *) mmap(0, sizeof *lock, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, 0, 0);

    if (lock == (lock_t *) -1) {
        fprintf(stderr, "mmap failed\n");
        return EXIT_FAILURE;
    }

    pthread_mutex_init(&lock->mutex, &mutex_attr);
    pthread_cond_init(&lock->cond, &cond_attr);

    pid = fork();

    if (pid == -1) {
        fprintf(stderr, "fork failed\n");
        return EXIT_FAILURE;
    } else if (pid == 0) {
        int i;

        for (i = 0; i < 100000; i++) {
            pthread_mutex_lock(&lock->mutex);
            pthread_cond_wait(&lock->cond, &lock->mutex);
            pthread_mutex_unlock(&lock->mutex);
            printf("child: %d\n", i);
        }
        _exit(0);
    } else {
        int i;

        for (i = 0; i < 100000; i++) {
            pthread_mutex_lock(&lock->mutex);
            pthread_cond_signal(&lock->cond);
            pthread_mutex_unlock(&lock->mutex);
            printf("parent: %d\n", i);
        }
        _exit(0);
    } 

    /* notreached */
    return 0;
}


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