bug-glibc
[Top][All Lists]
Advanced

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

bug in linuxthreads


From: Rustam Gallyamov
Subject: bug in linuxthreads
Date: Wed, 17 Sep 2003 18:39:00 +0400
User-agent: KMail/1.5.2

Hello!

It seems that POSIX threads implementation in glibc library in Mandrake 9.1 is 
buggy.
I was surprised when discovered that pthread_mutex_lock() is a cancelation 
point.

My system is:
Intel P3
kernel 2.4.21-0.18mdk
glibc-2.3.1-10mdk
gcc-3.2.2-3mdk

Here is a simple example.

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

pthread_t t1;
pthread_mutex_t mut = {0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 
__LOCK_INITIALIZER};

void   func_cleanup(void * unused)
{
        printf("*** Thread interrupted.\n");
        fflush(stdout);
}

void * func(void * unused)
{
        pthread_cleanup_push(func_cleanup, NULL);
        
        if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
                fprintf(stderr, "pthread_setcanceltype() failed\n");
                fflush(stderr);
                pthread_exit(NULL);
        }
        
        printf("Thread started.\n");
        fflush(stdout);
        
        pthread_mutex_lock(&mut);
        
        pthread_mutex_unlock(&mut);
        
        printf("Thread finished.\n");
        fflush(stdout);
        
        pthread_cleanup_pop(0);
        
        return NULL;
}

int main(int argc, char ** argv)
{
        int ret = 0;
        pthread_mutex_lock(&mut);
        
        ret = pthread_create(&t1, NULL, func, NULL);
        if (ret) {
                fprintf(stderr, "pthread_create 1 failed: %s\n", strerror(ret));
                fflush(stderr);
                exit(1);
        }
        
        sleep(1);
        
        pthread_cancel(t1);
        printf("Sent cancel request to thread 1.\n");
        fflush(stdout); 
        
        sleep(2);
        
        pthread_mutex_unlock(&mut);
        printf("Mutex unlocked.\n");
        fflush(stdout); 
        
        sleep(1);
        
        pthread_join(t1, NULL);
        printf("Thread joined.\n");
        fflush(stdout);
        
        return 0;
}


Compiled
gcc -Wall s.c -o s -lpthread

Here is output:

address@hidden test_threads]# ./s
Thread started.
Sent cancel request to thread 1.
*** Thread interrupted.
Mutex unlocked.
Thread joined.
address@hidden test_threads]#


This bug didn't appear on Gentoo 1.4.2.9 (glibc 2.3.1-r4, kernel 
2.4.20-gentoo-r5), Slackware (glibc 2.3.1, kernel 2.4.21-custom) and ASP 
Linux (glibc 2.2.5 kernel, kernel 2.4.18).

Attachment: s.c
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]