01-23-04 10:36 PM
Hi,
I have redhat 9.0 Linux installed on my system with gcc 3.2.3.
This is the program i used, i compiled it with -lpthread option.
Here i am starting 3 threads and then i am calling pthread_kill on a
thread which is non-existent , the signal being passed is '0'.
According to the POSIX standard if the thread doesn't exist it should
set errno to ESRCH. But instead it causes a segmentation fault.
Why is that ???
Is there any work around to this problem ???
Is this a linux problem or just Redhat 9.0 problem???
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include<signal.h>
#include <errno.h>
void* do_loop(void* data)
{
long int i;
int j;
int me = *((int*)data);
while (1) // infinite loop
{
i++;
if( i%1000000== 0)
printf("thread %d - i val %d\n", me, i);
if(i==225000000)
pthread_exit(NULL);
}
pthread_exit(NULL); // There is no point of this actually
}
int main()
{
int thr_id;
pthread_t id;
int a = 1;
int b = 2;
int c = 3;
int d = 4;
if(pthread_create(&id, NULL, do_loop, (void*)&a) != 0)
printf(" Thread creation Failure \n");
if(pthread_create(&id, NULL, do_loop, (void*)&c) != 0)
printf(" Thread creation Failure \n");
if(pthread_create(&id, NULL, do_loop, (void*)&d) != 0)
printf(" Thread creation Failure \n");
if(pthread_kill((pthread_t)19820, 0) == ESRCH)
{
printf("Main Thread: Thread not found \n");
}
else
{
printf(" Thread Found !!!.... Killing\n");
sleep(10);
pthread_kill(id,SIGKILL);
}
return 0;
}
//P.S : This very same program works on Solaris!!!
[ Post a follow-up to this message ]
|