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!!!
|
|
0
|
|
|
|
Reply
|
anoop_kn (5)
|
1/23/2004 11:39:18 AM |
|
anoop_kn@yahoo.com (Anoop Kumar) writes:
> 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
|
|
0
|
|
|
|
Reply
|
mru
|
1/23/2004 11:54:32 AM
|
|
M�ns Rullg�rd wrote:
> anoop_kn@yahoo.com (Anoop Kumar) writes:
>
>
>>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.
BTW -- compile with `-pthread', not `-lpthread' (though it's not
directly relevant here it will avoid other potential problems).
>>
>>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.
>
--ag
--
Artie Gold -- Austin, Texas
|
|
0
|
|
|
|
Reply
|
Artie
|
1/23/2004 2:46:58 PM
|
|
|
2 Replies
570 Views
(page loaded in 0.153 seconds)
Similiar Articles: What is wrong with pthread_kill on Redhat Linux ??? - comp.unix ...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 startin... remsh between HPUX and Linux - comp.sys.hp.hpuxWhat is wrong with pthread_kill on Redhat Linux ??? - comp.unix ... remsh between HPUX and Linux - comp.sys.hp.hpux What is wrong with pthread_kill on Redhat Linux ... system() call on linux causes errno set to SIGCHLD - comp.unix ...What is wrong with pthread_kill on Redhat Linux ??? - comp.unix ... system() call on linux causes errno set to SIGCHLD - comp.unix ... What is wrong with pthread_kill on ... why doesn't wprintf work - comp.unix.programmerWhat is wrong with pthread_kill on Redhat Linux ??? - comp.unix ..... to the POSIX standard if the thread doesn't ... Why is that ??? Is there any work around to this ... Problem with pthreads C++ wrapper class on Linux - comp ...What is wrong with pthread_kill on Redhat Linux ??? - comp.unix ... Problem with pthreads C++ wrapper class on Linux - comp ... What is wrong with pthread_kill on Redhat ... linux shared memory synchronization objects - comp.unix.programmer ...... out so many things, tell me, is it POSSIBLE in linux 2 ... in conjunction with posix semaphores, and pthread ... kernel(+ the userspace libraries). And the latest RedHat ... Segmentation fault on trying to deliver to bighotpay.com - comp ...I am running the latest updates for Red Hat Enterprise Linux ES release 4 (Nahant Update 8) sendmail-8.13.1-3.3.el4 What is going wrong with sendmail in this case? remote X session from Linux to HPUX - comp.sys.hp.hpuxAnother problem I'm facing is that of a wrong colormap between the ... The "client" I'm talking about is a Linux box, running debian (or redhat, no matter) and I start the ... NFS slowdown - Solaris client, Linux server. - comp.unix.solaris ...If you're alluding at me, you just picked a wrong person to label. I've worked ... comp.unix.solaris | Computer Group Help: RCP issue between solaris and redhat linux ... HP 58503A GPS receiver question - comp.protocols.time.ntp ...... and unrecognized time code format T1 > Can anyone tell what is wrong here? > The ... comp.protocols.time.ntp Hi Is there any good SNTP client available in Redhat Linux ? What is wrong with pthread_kill on Redhat Linux ??? - comp.unix ...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 startin... POSIX thread (pthread) libraries - YoLinux.com: Linux Tutorials ...POSIX Pthread libraries on Linux. YoLinux: Linux Information Portal includes informative tutorials and links to many Linux sites. 7/23/2012 9:20:19 AM
|