- 9
- 0
- 约7.71千字
- 约 32页
- 2017-01-28 发布于湖北
- 举报
信号量与PV操作全解
item B[k]; semaphore empty; empty=k; //可以使用的空缓冲区数 semaphore full; full=0; //缓冲区内可以使用的产品数 int in=0; //放入缓冲区指针 int out=0; //取出缓冲区指针? cobegin process producer ( ){ while(true) { produce( ); P(empty); append to B[in]; in=(in+1)%k; V(full); } } coend ? * process consumer ( ){ while(true) { P(full); take( ) from B[out]; out=(out+1)%k; V(empty); consume( ); } } item B[k]; semaphore empty; empty=k; //可以使用的空缓冲区数 semaphore full; full=0; //缓冲区内可以使用的产品数 semaphore mutex; mutex=1; //互斥信号量 int in=0; //放入缓冲区指针 int out=0; //取出缓冲区指针? cobegin process producer_i ( ){ while(true) { produce( ); P(empty); P(mutex); append to B[in]; in=(in+1)%k; V(mutex); V(full); } } coend ? * process consumer_j ( ){ while(true) { P(full); P(mutex); take( ) from B[out]; out=(out+1)%k; V(mutex); V(empty); consume( ); } } 有两组并发进程:读者和写者,共享一个文件F,要求: 允许多个读者同时执行读操作 任一写者在完成写操作之前不允许其它读者或写者工作 写者执行写操作前,应让已有的写者和读者全部退出 * int readcount=0;
您可能关注的文档
最近下载
- 常微分方程(第四版)课件 王高雄 高等教育出版社 第一章 绪论.pptx VIP
- 第四单元-第二章-第一节 食物中的营养物质课件-2024-2025学年七年级生物下学期人教版202.pptx
- 新技术、新工艺、新材料及新理念在市政工程中的应用.ppt VIP
- 《四川麻将竞赛规则》(TTFMJ 01-2024).pdf VIP
- 大学语文 课件全套 吕澜希 第1--7章 先秦文学---外国文学.pptx
- 盈建科教学知识培训课件.pptx VIP
- 常微分方程(第四版)课件 王高雄 高等教育出版社 第二章 一阶微分方程的初等解法(一).pptx VIP
- 现代产品设计与开发第7章 CMF设计的材料与工艺.pptx VIP
- 【教案】八年级 第16课 模块功能先划分.docx VIP
- 离散数学(微课版)(第2版).pptx
原创力文档

文档评论(0)