signal pthread_kill

#include <stdio.h>
#include <pthread.h>
#include <signal.h>


#define SIGNALE_SIG (SIGRTMAX - 4)


int iSwitch = 0;


void *threadfunc1(void *pvoid)

int signum;
sigset_t sig;
sigemptyset(&sig);
sigaddset(&sig,SIGNALE_SIG);
pthread_sigmask(SIG_BLOCK,&sig,NULL);//设置该线程的信号屏蔽字为SIGUSR1
while(1)
{
        if (0 == iSwitch)
{
            sigwait(&sig,&signum);//睡眠等待SIGUSR1信号的到来
        }
        else
        {
            printf("test, and bSwitch == %d\n", iSwitch);
        }
}
}


void main()
{
pthread_t thread1,thread2;
pthread_create(&thread1,NULL,threadfunc1,(void *)NULL);
    //pthread_create(&thread2,NULL,threadfunc2,(void *)NULL);


    //pthread_detach(thread1);
    //pthread_detach(thread2);


   struct sigaction act;
   act.sa_handler=SIG_IGN;
   sigemptyset(&act.sa_mask);
   act.sa_flags=0;
   sigaction(SIGNALE_SIG,&act,0);//设置信号SIGUSR1的处理方式忽略


   iSwitch = 1;
   pthread_kill(thread1,SIGNALE_SIG);


   while(1){}
}

//编译 gcc -o pthread pthread.c -lpthread



http://www.cnblogs.com/liulipeng/p/3555450.html

http://blog.youkuaiyun.com/qq_695538007/article/details/9153179

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值