Open System Services Programmer's Guide

Example 63 Handling the Synchronous Signal SIGFPE
/* This test program demonstrates handling the */
/* SIGFPE synchronous signal. */
/* You must also export the environment variable **/
/* SPT_THREAD_AWARE_SIGNAL to 1 to **/
/** enable thread-aware signal handling **/
#define SPT_THREAD_AWARE /** enables thread aware behavior **/
#define SPT_THREAD_SIGNAL /** maps signal() to spt_signal()**/
#include <spthread.h>
/*Define a signal handler for this thread */
void sighand(int signo);
int x=10,y=0,z;
void *threadfunc(void *parm)
/* Perform the illegal operation of dividing by zero and */
/* raise the SIGFPE signal. The SIGFPE signal is sent to */
/* the generic handler. */
{
signal(SIGFPE,sighand);
z = x/y;
printf("\nI am in thread1\n");
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread1;
int rc;
printf("Enter Testcase - %s\n", argv[0]);
/* create the thread */
pthread_create(&thread1, NULL, threadfunc, NULL);
sleep(1);
printf("Wait for threads to complete\n");
pthread_join(thread1, NULL);
printf("Main completed\n");
return 0;
}
void sighand(int signo)
{
printf("Signal received is %d\n",signo);
}
320 Using the Standard POSIX Threads Library