/*
WRONG SIGNAL HANDLER CALLED FOR THREADS
Following code sample will show the problems I have with Solaris 2.4 x86
threads and cancelation. I know that Posix threads with cancelation will
be in 2.5 but it will not be availiable in retail before december.
It look like the correct thread is signaled, but the last signal handler
installed is called (at least the first time)
anybody have a idea about what I am doing wrong ?
Or is it a bug ?
List of CC -V
-----------------------------------
CC: PC3.0.1 21 Jan 1995
ccfe: PC3.0.1 21 Jan 1995 C++4.0.1
as: PC3.0.1 21 Jan 1995
tdb_link: PC3.0.1 21 Jan 1995 C++4.0.1
-----------------------------------
Program Output:
Main Running
thread1 started
thread2 started
thread3 started
Killing thread1 Sighan3 QUIT
thread1 ready
Killing thread2 Sighan1 QUIT
thread2 ready
Killing thread3 Sighan1 QUIT
thread3 ready
Main Ready
regards
Arne Varholm
*/
#include <stdio.h>
#include <unistd.h>
#include <thread.h>
#include <signal.h>
////////////////////////////
void enable_SIG(int sig)
{
sigset_t mask;
sigfillset(&mask); // exclude all signals
sigdelset(&mask,sig);
thr_sigsetmask(SIG_SETMASK,&mask,NULL);
////////////////////////////Quote:}
void sighan1(int sig)
{
char msg[10];
sig2str(sig,msg);
printf("Sighan1 %s\n",msg);
signal(sig,sighan1);
enable_SIG(sig);
void sighan2(int sig)Quote:}
{
char msg[10];
sig2str(sig,msg);
printf("Sighan2 %s\n",msg);
signal(sig,sighan1);
enable_SIG(sig);
void sighan3(int sig)Quote:}
{
char msg[10];
sig2str(sig,msg);
printf("Sighan3 %s\n",msg);
signal(sig,sighan1);
enable_SIG(sig);
////////////////////////////Quote:}
void* thread1(void* par)
{
signal(SIGQUIT,sighan1);
enable_SIG(SIGQUIT);
puts("thread1 started");
sleep(9999); // Block
puts("thread1 ready");
return par;
void* thread2(void* par)Quote:}
{
signal(SIGQUIT,sighan2);
enable_SIG(SIGQUIT);
puts("thread2 started");
sleep(9999); // Block
puts("thread2 ready");
return par;
void* thread3(void* par)Quote:}
{
signal(SIGQUIT,sighan3);
enable_SIG(SIGQUIT);
puts("thread3 started");
sleep(9999); // Block
puts("thread3 ready");
return par;
////////////////////////////Quote:}
main()
{
thread_t thr1,thr2,thr3;
puts("Main Running");
thr_create(NULL,0,thread1,NULL,0,&thr1);
thr_create(NULL,0,thread2,NULL,0,&thr2);
thr_create(NULL,0,thread3,NULL,0,&thr3);
sleep(3);
printf("Killing thread1 ");
thr_kill(thr1,SIGQUIT);
thr_join(thr1,NULL,NULL);
printf("Killing thread2 ");
thr_kill(thr2,SIGQUIT);
thr_join(thr2,NULL,NULL);
printf("Killing thread3 ");
thr_kill(thr3,SIGQUIT);
thr_join(thr3,NULL,NULL);
puts("Main Ready");
/* EOF */Quote:}