#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <semaphore.h>
#include <sys/stat.h>
void Testfun(sem_t* sem1)
{
static int num = 0;
for(;;)
{
sem_wait(sem1);
printf("this is sem1 fun num =%d\n",num);
num++;
sem_post(sem1);
sleep(2);
}
}
int main(void)
{
sem_unlink("sem_open1");
sem_t *sem1;
sem1 = sem_open("sem_open1",O_CREAT | O_RDWR,0666,1);
if(sem1 == NULL)
perror("sem1 open");
Testfun(sem1) ;
return 0;
}