sigwait和pthread_kill的使用.只发了一个信号阿?怎么有等到两个????
- C/C++ code
/*********************************************************************************//* 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.outin pthread:35aa b7f50b90the num of signo is 2 in main:35aa b7f516c00 [root@localhost niwen]# 只发了一个信号阿?怎么有等到两个????[解决办法]
友情帮顶
[解决办法]
建议lz仔细阅读sigwait的文档
[解决办法]
in pthread:227b b75e0b70
我的机子上只输出这个.
SIGINT 换成SIGUSER1
in pthread:22d8 b7699b70
用户定义信号 1
[解决办法]
呵呵,