日期:2014-05-16 浏览次数:20718 次
/*********************************************************************************/ /* sigwait和pthread_kill的使用 */ /********************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <pthread.h> void * fun(void * arg) { int *p = (int *)arg; printf("in pthread:%x %x\n", getpid(), pthread_self()); pthread_kill(*p, SIGINT); return (void *)0; } int main() { pthread_t tid; int err; sigset_t st; int ptid; int num; sigfillset(&st); ptid = pthread_self(); if ((err = pthread_create(&tid, NULL, fun, (void *)(&ptid))) != 0) { printf("pthread error!\n"); } if (sigwait(&st, &num) != 0) { printf("sigwait error!\n"); } //只发了一个信号阿?怎么有等到两个???? printf("the num of signo is %d \n", num); //sleep(3); printf("in main:%x %x\n", getpid(), pthread_self()); printf("%d \n", pthread_equal(tid, pthread_self())); return 0; } 运行结果: [root@localhost niwen]# gcc 1.c -lpthread [root@localhost niwen]# ./a.out in pthread:35aa b7f50b90 the num of signo is 2 in main:35aa b7f516c0 0 [root@localhost niwen]# 只发了一个信号阿?怎么有等到两个????