linux中进程问题
#include <stdio.h> #include<string.h> #include <semaphore.h> #include <pthread.h> #include <windows.h> #include <unistd.h> sem_t empty; //定义信号量 sem_t applefull; sem_t orangefull; void *procf(void *arg) //father线程 { while(1){ sem_wait(∅); //P操作 printf("%s\n",(char *)arg); sem_post(&applefull;); //V操作 Sleep(7); } } void *procm(void *arg) //mother线程 { while(1){ sem_wait(∅); printf("%s\n",(char *)arg); sem_post(&orangefull;); Sleep(3); } } void *procs(void *arg) //son线程 { while(1){ sem_wait(&orangefull;); printf("%s\n",(char *)arg); sem_post(∅);sleep(2); } } void *procd(void *arg) //daughter线程 { while(1){ sem_wait(&applefull;); printf("%s\n",(char *)arg); sem_post(∅);sleep(5); } } main() { pthread_t father; //定义线程 pthread_t mother; pthread_t son; pthread_t daughter; sem_init(∅, 0, 1); //信号量初始化 sem_init(&applefull;, 0, 0);
- 粉丝: 0
- 资源: 1
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助