在线
客服

发布
需求

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

求修改一下这个理发师问题程序,运行有7个报错


#include
#include
#include"unistd.h"
//#ifndef "unistd.h" #define "unistd.h" #include  #include #endif /* _UNISTD_H */
//#include"pthread.h"
#include"semaphore.h"
#include"fcntl.h"
#include "errno.h"
#define N 5
//引入3个信号量:mutex,customers,barbers;
sem_t mutex,customers,barber;
int waiting =0;
int chair [5];
void *barbers();
void *customer();
int main(int argc,char *argv[])
//定义10个信号量和一个理发师信号量
pthread_t Customer_id[10],Barbers_id;
int i;
sem_init(&mutex,0,1); //init mutex semaphore to 1
sem_init (&barber,0,1);
sem_init(&customers,0,0);
//init semaphore customers to 0

//creat barber pthread
void *barber()
{int i;
int next;
//wait(customers),如果没有顾客,理发师休息
sem_wait(&customers)
sem_wait (&mutex)
//wait(mutex)
waiting--;
//the number of waiting reduce one
for(i=0,i

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖
国内首家创新型IT技术需求众包服务平台,软件需求就上天盟网! 立即登录 立即注册