00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "defs.h"
00027
00028 #if _POSIX_REALTIME_SIGNALS > 0
00029
00030 #include <pthread.h>
00031
00032
00033 #define MYSIG_COUNT SIGRTMIN
00034 #define MYSIG_STOP SIGRTMIN + 1
00035
00036 static void *sig_thread(void *arg)
00037 {
00038 int signum;
00039 siginfo_t info;
00040
00041 do {
00042 signum = sigwaitinfo((sigset_t *)arg, &info);
00043 if (signum == MYSIG_COUNT)
00044 printf("Got MYSIG_COUNT; value: %s\n",
00045 (char *)info.si_value.sival_ptr);
00046 else if (signum == MYSIG_STOP) {
00047 printf("Got MYSIG_STOP; terminating thread\n");
00048 return (void *)true;
00049 }
00050 else
00051 printf("Got %d\n", signum);
00052 } while (signum != -1 || errno == EINTR);
00053 EC_FAIL
00054
00055 EC_CLEANUP_BGN
00056 EC_FLUSH("sig_thread")
00057 return (void *)false;
00058 EC_CLEANUP_END
00059 }
00060
00061 static void dummy_handler(int signum, siginfo_t *info, void *context)
00062 {
00063 }
00064
00065 int main(void)
00066 {
00067 sigset_t set;
00068 struct sigaction act;
00069 union sigval value;
00070 pthread_t tid;
00071
00072 #ifdef LINUX
00073 printf("Warning: May hang -- see comment at the top of c9/thrq.c\n");
00074 #endif
00075 ec_neg1( sigemptyset(&set) )
00076 ec_neg1( sigaddset(&set, MYSIG_COUNT) )
00077 ec_neg1( sigaddset(&set, MYSIG_STOP) )
00078 ec_rv( pthread_sigmask(SIG_SETMASK, &set, NULL) )
00079 memset(&act, 0, sizeof(act));
00080 act.sa_flags = SA_SIGINFO;
00081 act.sa_sigaction = dummy_handler;
00082 ec_neg1( sigaction(MYSIG_COUNT, &act, NULL) )
00083 ec_neg1( sigaction(MYSIG_STOP, &act, NULL) )
00084 value.sival_ptr = "One";
00085 ec_neg1( sigqueue(getpid(), MYSIG_COUNT, value) )
00086 value.sival_ptr = "Two";
00087 ec_neg1( sigqueue(getpid(), MYSIG_COUNT, value) )
00088 value.sival_ptr = "Three";
00089 ec_neg1( sigqueue(getpid(), MYSIG_COUNT, value) )
00090 value.sival_ptr = NULL;
00091 ec_neg1( sigqueue(getpid(), MYSIG_STOP, value) )
00092 ec_rv( pthread_create(&tid, NULL, sig_thread, &set) )
00093 ec_rv( pthread_join(tid, NULL) )
00094 exit(EXIT_SUCCESS);
00095
00096 EC_CLEANUP_BGN
00097 exit(EXIT_FAILURE);
00098 EC_CLEANUP_END
00099 }
00100
00101
00102 #else
00103
00104 int main(void)
00105 {
00106 printf("Not supported.\n");
00107 exit(1);
00108 }
00109
00110 #endif