|
Home > Archive > Unix Programming > January 2004 > What is wrong with pthread_kill on Redhat Linux ???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
What is wrong with pthread_kill on Redhat Linux ???
|
|
| Anoop Kumar 2004-01-23, 5: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!!!
| |
| =?iso-8859-1?q?M=E5ns_Rullg=E5rd?= 2004-01-23, 5:36 pm |
| anoop_kn@yahoo.com (Anoop Kumar) writes:
quote:
> 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???
It's a weakness in the new NPTL thread library used by redhat 9.
pthread_kill and a few other functions cast the pthread_t to a pointer
and attempt to dereference it. Obviously, this will cause a
segmentation fault. The only workaround I can think of is not to pass
invalid thread IDs to these functions.
--
Måns Rullgård
mru@kth.se
| |
| Artie Gold 2004-01-23, 5:36 pm |
| Måns Rullgård wrote:quote:
> anoop_kn@yahoo.com (Anoop Kumar) writes:
>
>
BTW -- compile with `-pthread', not `-lpthread' (though it's not
directly relevant here it will avoid other potential problems).
[QUOTE][color=darkred]
>
>
> It's a weakness in the new NPTL thread library used by redhat 9.
> pthread_kill and a few other functions cast the pthread_t to a pointer
> and attempt to dereference it. Obviously, this will cause a
> segmentation fault. The only workaround I can think of is not to pass
> invalid thread IDs to these functions.
>
--ag
--
Artie Gold -- Austin, Texas
|
|
|
|
|