#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 =%dn",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;
}
最后
以上就是英勇黑夜最近收集整理的关于有名信号量的全部内容,更多相关有名信号量内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复