当前位置: 技术问答>linux和unix
Linux中pthread_join等待无法返回
来源: 互联网 发布时间:2017-05-03
本文导语: #include #include #include #include pthread_t ntid; sigset_t set; void *child_thread(void *p) { int signum; while(1) { sigwait(&set, &signum); switch(signum) { case SIGUSR1: printf("pthread running.n"); continue; case SIGUSR2: pr...
#include
#include
#include
#include
pthread_t ntid;
sigset_t set;
void *child_thread(void *p)
{
int signum;
while(1)
{
sigwait(&set, &signum);
switch(signum)
{
case SIGUSR1:
printf("pthread running.n");
continue;
case SIGUSR2:
printf("sleep 2s quit.n");
sleep(1);
break;
default:
printf("no symbol..n");
}
}
sigdelset(&set, SIGUSR2);
}
int main()
{
int retu;
char tmpc;
void *status;
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGUSR2);
sigprocmask(SIG_SETMASK,&set,NULL);
retu = pthread_create(&ntid, NULL, child_thread, NULL);
if(retu
#include
#include
#include
pthread_t ntid;
sigset_t set;
void *child_thread(void *p)
{
int signum;
while(1)
{
sigwait(&set, &signum);
switch(signum)
{
case SIGUSR1:
printf("pthread running.n");
continue;
case SIGUSR2:
printf("sleep 2s quit.n");
sleep(1);
break;
default:
printf("no symbol..n");
}
}
sigdelset(&set, SIGUSR2);
}
int main()
{
int retu;
char tmpc;
void *status;
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGUSR2);
sigprocmask(SIG_SETMASK,&set,NULL);
retu = pthread_create(&ntid, NULL, child_thread, NULL);
if(retu