Solaris 2.4 x86 Threads, Wrong signal handler called with thr_kill()

Solaris 2.4 x86 Threads, Wrong signal handler called with thr_kill()

Post by Arne Varho » Sat, 16 Sep 1995 04:00:00



/*
               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);
Quote:}

void sighan2(int sig)
{
        char msg[10];
        sig2str(sig,msg);
        printf("Sighan2 %s\n",msg);
        signal(sig,sighan1);
        enable_SIG(sig);
Quote:}

void sighan3(int sig)
{
        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;
Quote:}

void* thread2(void* par)
{
        signal(SIGQUIT,sighan2);
        enable_SIG(SIGQUIT);
        puts("thread2 started");
        sleep(9999);    // Block
        puts("thread2 ready");
        return par;
Quote:}

void* thread3(void* par)
{
        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");

Quote:}

/* EOF */
 
 
 

1. Problem between signal handlers and thread library on Solaris 2.4

I've encountered a problem setting up signal handlers whenever I
use the Solaris 2.4 thread library (-lthread). A very blatant example
of this occurs in the case of SIGTSTP. Consider the following program:

#include <signal.h>

void sigHandler(int sig, siginfo_t *info, void *arg)
{
        printf ("sig %d caught\n", sig);

main()
{
        struct sigaction new;

        new.sa_handler = sigHandler;
        new.sa_flags = 0;
        sigemptyset(&new.sa_mask);
        if (sigaction (SIGTSTP, &new, (struct sigaction*)0) < 0)
         { perror ("sigaction");
         }
        while (1)
         { sleep(1);
         }

If I compile and load this using

% cc -o test test.c

then everything works fine: whenever the program receives a SIGSTP the
handler gets called and its message is printed. But if I compile using

% cc -D_REENTRANT -o systest systest.c -lthread

the SIGSTP is ignored.

I'm new to working with threads and so of course I may have missed
some crucial detail, but a couple of passes through the manuals haven't
turned up anything. By poking around with debuggers I have figured
out the when you link in -lthread the program automatically starts
up an invisible LWP, and a couple of threads, and *these* appear
to take over the signal handling for the program. And in fact the signal
*is* received by the internal LWP. However, for some reason it is not
being passed on the main program.

Any information would be greatly appreciated.

Thanks!

John Lloyd                                  Tel: (604) 822-5109 (office)
Department of Computer Science              Msg: (604) 822-6281 (LCI office)
201 - 2366 Main Mall                        Fax: (604) 822-5485

Vancouver, B.C.  V6T 1Z4                    Office: CICSR 129

2. IPFIREWALL x IPFILTER

3. Threads performance - allow signal handler to not call handler

4. Promise IDE ATA-100 controller on ASUS A7V133

5. --- called from signal handler with signal -24242176 (SIG Unknown)

6. pppd getting dropped unexpectedly

7. Reentrant system calls (can be called from signal handler)

8. Maximum Fixed address entry for DHCP

9. deadlock Solaris 2.5.1 malloc called from Signal handler

10. solaris 2.4: monitoring tools/api calls for threaded processes?

11. Signal handlers inside signal handlers

12. Solaris undetached threads and thr_kill()

13. how to deal with thread-specific data in signal handler?