第五讲进程同步和通信(partII).pptVIP

  • 4
  • 0
  • 约1.31万字
  • 约 60页
  • 2017-11-24 发布于江苏
  • 举报
第五讲进程同步和通信(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)

1亿VIP精品文档

相关文档