#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
pthread_t pthid1,pthid2;
void handler(int arg){
return;
}
static void * fun1(void *arg){
signal(SIGUSR1,handler);
pause();
puts("second");
return NULL;
}
static void * fun2(void *arg){
sleep(1);
puts("first");
pthread_kill(pthid1,SIGUSR1);
return NULL;
}
int main(int argc, const char *argv[])
{
if(0 != pthread_create(&pthid1,NULL,fun1,NULL)){
perror("pthid1");
return -1;
}
if(0 != pthread_create(&pthid2,NULL,fun2,NULL)){
perror("pthid2");
return -1;
}
pthread_join(pthid1,NULL);
pthread_join(pthid2,NULL);
return 0;
}
上例实现了两个线程的同步