Port-powerpc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pthread mutex failures



Is there any chance to fix the critical PR44387 before 6.0 is released?

I can reproduce it on several macppc, ofppc and sandpoint platforms, but
unfortunately I have no idea how to fix it. The bug timing-critical, which
means using gdb or generating more debugging output will make it disappear
in most cases.

For easier analysis of the problem I made a simple standalone program,
without the ATF framework:

#include <sys/cdefs.h>
#include <pthread.h>
#include <stdio.h>

static pthread_mutex_t mutex;
static int global_x;

static void *
threadfunc(void *arg)
{
        long count = *(int *)arg;

        printf("Second thread (%p). Count is %ld\n", pthread_self(), count);

        while (count--) {
                pthread_mutex_lock(&mutex);
                global_x++;
                pthread_mutex_unlock(&mutex);
        }
        return (void *)count;
}

int main()
{
        pthread_t new;
        void *joinval;
        int count, count2;

        printf("Mutex-test\n");
        pthread_mutex_init(&mutex, NULL);

        global_x = 0;
        count = count2 = 10000000;

        pthread_mutex_lock(&mutex);
        pthread_create(&new, NULL, threadfunc, &count2);
        printf("Thread: %p\n", pthread_self());
        pthread_mutex_unlock(&mutex);

        while (count--) {
                pthread_mutex_lock(&mutex);
                global_x++;
                pthread_mutex_unlock(&mutex);
        }

        pthread_join(new, &joinval);
        pthread_mutex_lock(&mutex);
        printf("Thread joined. X was %d. Return value (long) was %ld\n",
                global_x, (long)joinval);

        return (long)joinval != -1;
}

-- 
Frank Wille


Home | Main Index | Thread Index | Old Index