- 2
- 0
- 约1.31万字
- 约 60页
- 2018-07-09 发布于江苏
- 举报
第五讲进程同步与通信partII
Readers-Writers problem (cont’d) 写者对共享数据具有独占性 读者-写者问题的变形: The first R/W problem Reader has the higher priority Writer may starve The second R/W problem Writer has the higher priority Reader may starve R/W problem: a solution Shared variable int readcount = 0; Shared semaphore semaphore Wmutex=1; semaphore Rmutex = 1; Writer do{ P(Wmutex); /* perform write operation */ V(Wmute); }while(1); Reader do{ P(Rmutex); if (readcount==0) P(Wmutex); readcount++; V(Rmutex); /* perform read operation */ P(Rmutex); readcount--; if (readcount==0) V(Wmutex); V(Rmutex); }while(1); 利用
原创力文档

文档评论(0)