bug-glibc
[Top][All Lists]
Advanced

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

NPTL thread cancellation Abort problem with UL1.0 binary run on RHEL3U1


From: Sachin Sant
Subject: NPTL thread cancellation Abort problem with UL1.0 binary run on RHEL3U1
Date: Thu, 26 Feb 2004 11:27:22 +0530

Hi i have a test program which uses thread library. I compile the 
program on a linux system with linuxthreads library. When i try to use 
the same binary on a RHEL system with NPTL i am facing a problem.
The program core dumps.

Here is the output with linuxthreads

$ ./nptl
  X()
  Hello World!
  ~X()
  test_cleanup
$

Here is the output with NPTL

$ ./nptl
  X()
  Hello World!
  Abort
$

Here is the test program.

----------------Makefile-----------------
nptl: nptl.cpp
        g++ -o nptl nptl.cpp -lpthread

------------Test Program, ntpl.cpp-------
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

class X {
public:
    X()
    {
        char        buf[] = "X()\n";

        (void) write(1, buf, sizeof (buf) - 1);
    }
    ~X()
    {
        char        buf[] = "~X()\n";

        (void) write(1, buf, sizeof (buf) - 1);
    }
};

void
test_cpp_thread(void)
{
    char        buf[10];
    char        buf1[] = "Hello World!\n";
    char        buf2[] = "Exception\n";
    X           x;

    try {
        (void) write(1, buf1, sizeof (buf1) - 1);
        (void) read(0, buf, sizeof (buf));
        throw("Burp");
        pthread_exit(NULL);
    }
    catch (const char *crap) {
        (void) write(1, buf2, sizeof (buf2) - 1);
    }

    return;
}

extern "C" {

void
test_cleanup(void *arg)
{
    char        buf[] = "test_cleanup\n";

    (void) write(1, buf, sizeof (buf) - 1);

    return;
}

void *
test_thread(void *arg)
{
    pthread_cleanup_push(test_cleanup, NULL);

    test_cpp_thread();

    pthread_cleanup_pop(0);

    return (NULL);
}

};

int main(
    int         argc,
    char        *argv[])
{
    pthread_t   thread_h;
    void        *thread_return = NULL;

    (void) pthread_create(&thread_h, NULL, test_thread, NULL);

    sleep(4);

    (void) pthread_cancel(thread_h);
    (void) pthread_join(thread_h, &thread_return);
    return (0);
}


If i change the read( ) call to pthread_cond_wait( ) , the compiled 
runs OK on RHEL3U1.  

Can someone help be with this problem.

-- 
Thanks
-Sachin




reply via email to

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