| CODE |
#include <pthread.h> #include <stdio.h> #include <signal.h> #include <unistd.h> void * foo (void *); void bar (int); int main (int argc,char ** argv) { pthread_t f_tid; bar (SIGALRM); if (pthread_create (&f_tid,NULL,&foo,"Billy boy") == 0) { for (;;) { sleep (1); if (pthread_kill (f_tid,SIGALRM) != 0) { printf ("error : can't send signal, aborting.\n"); break; } } } return 0; } void * foo (void * p) { int i = 0; for (;;) { pause (); printf ("%d) Good morning %s!\n",++i,p != NULL ? (char *)p : "foo"); } return NULL; } void bar (int sn) { signal (SIGALRM,bar); } |
| CODE |
| uname -a Linux <machineName> 2.4.9-21smp #1 SMP Thu Jan 17 14:01:48 EST 2002 i686 unknown |
| CODE |
| if (pthread_create (&f_tid,NULL,&foo,(void*)"Billy boy") == 0) |
| CODE |
| printf("Setting signal %d\n",sn); |
| CODE |
| > g++ sig.cpp -lpthread > ./a.out Setting signal 14 Setting signal 14 1) Good morning Billy boy! Setting signal 14 2) Good morning Billy boy! Setting signal 14 3) Good morning Billy boy! Setting signal 14 4) Good morning Billy boy! Setting signal 14 5) Good morning Billy boy! Setting signal 14 6) Good morning Billy boy! |