[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Thread bug when trying to delete thread specific data
From: |
Robert Schweikert |
Subject: |
Thread bug when trying to delete thread specific data |
Date: |
Tue, 12 Mar 2002 19:01:43 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020216 |
Hi,
I couldn't review the bug database, sorry couldn't figure out how to
make it work for me. Thus this bug may already be filed and or fixed.
When compiling the following code and runing it on a 2 CPU PII, PIII, or
PIV system the program crashes of and on in pthread_key_delete(). Since
this does not happen all the time I think there is a race condition
somewhere.
#include <sched.h>
#include <pthread.h>
#include <stdio.h>
void testkey()
{
pthread_key_t my_key;
fprintf(stderr,"testkey: started\n");
pthread_key_create(&my_key, 0);
fprintf(stderr,"testkey: key created\n");
pthread_key_delete(my_key);
fprintf(stderr,"testkey: done\n");
}
void* _thread(void* arg)
{
fprintf(stderr,"thread started\n");
testkey();
fprintf(stderr,"thread done\n");
return 0;
}
int main( int argc, char **argv )
{
pthread_t tid;
pthread_attr_t attr;
fprintf(stderr,"main starts\n");
testkey();
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
fprintf(stderr,"creating thread\n");
pthread_create(&tid, 0, _thread, 0);
fprintf(stderr,"thread created\n");
pthread_join(tid, 0);
fprintf(stderr,"main done\n");
return 0;
}
This was compiled as follows
gcc -pthread -o ptest ptest.c -lpthread
And produces the following traceback
#0 0x40030170 in pthread_key_delete () from /lib/libpthread.so.0
#1 0x080486af in testkey ()
#2 0x080486f1 in _thread ()
#3 0x4002cf37 in pthread_start_thread () from /lib/libpthread.so.0
This happens about 2 in 10 times. he code is compiled with gcc-2.95.3.
When the example runs one can see the print statements in relatively
fast order, while when the code dumps it appears as if the code is pausing.
Following the flow in the debugger I can see that from
pthread_key_delete() in specific.c it proceeds to __pthread_lock() in
spinnlock.c. From there it goes onto the following assembly code
PT_EI int
__compare_and_swap (long int *p, long int oldval, long int newval)
{
char ret;
long int readval;
__asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
: "=q" (ret), "=m" (*p), "=a" (readval)
: "r" (newval), "m" (*p), "a" (oldval)
: "memory");
return ret;
}
which is in pt-machine.h. Since I have no clue about assembly this is
all black magic to me. Anyway, this is where things go wrong. If I run
through the debugger the code of course never crashes, but with out the
debugger it dies.
Could someone please take a look and let me know if there is a patch
already, I'll be happy to try it, or if this can be fixed in the near
future. If a fix is not feasible any time soon I'll have to leak the
thread specific data in my code on Linux.
Thanks for your help.
Robert
--
Robert Schweikert MAY THE SOURCE BE WITH YOU
address@hidden LINUX
- Thread bug when trying to delete thread specific data,
Robert Schweikert <=