- 论坛徽章:
- 0
|
在主线程中创建一个定时器,在定时器线程中用sigwait函数捕捉不到主线程定时器超时产生的SIGALRM信号,代码如下:
void fun()
{
sigset_t mask;
int sig;
sigemptyset(&mask);
sigaddset(&mask, SIGALRM);
while(1)
{
//block here
sigwait(&mask, &sig);
sleep(50);
}
}
int main (int argc, const char * argv[]) {
pthread_t ticker;
struct timeval tv;
struct timeval new;
struct itimerval abc = {{0,0}, {0,0}};
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGALRM);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
pthread_create(&ticker, NULL, fun, NULL);
gettimeofday(&tv, NULL);
new.tv_sec = tv.tv_sec + 20;
abc.it_value.tv_sec = new.tv_sec - tv.tv_sec;
setitimer(ITIMER_REAL, &abc, NULL);
while(1)
{
sleep(100);
}
}
定时器线程会阻塞在sigwait函数上
怎么解决阻塞问题,求高手解答,谢谢!
|
|