homework参考答案.pptVIP

  • 99
  • 0
  • 约7.12千字
  • 约 36页
  • 2015-10-14 发布于河南
  • 举报
homework参考答案

第二章 6、答:设信号量empty用于表示空盘子的数量,信号量apple用于计数,表示盘子中的苹果数目,信号量orange用于计数,表示盘子中的桔子数目。 Semaphore empty=1,apple=0,orange=0 dad(){ while(1){ prepare an apple; P(empty); put an apple on the plate; V(apple ); }} 第二章 son(){ while(1) { P(orange); take an orange from the plate; V(empty); eat the orange; }} 第二章 7、答: 为了使写者优先,在原来的读优先算法基础上增加一个初值为1的信号量S,使得当至少有一个写者准备访问共享对象时,它可使后续的读者进程等待写完成; 初值为0的整型变量writecount,用来对写者进行计数;初值为1的互斥信号量wmutex,用来实现多个写者对writecount的互斥访问。 第二章 writer(){ while(1){ P(wmutex); if(writecount= =0) P(S); writecount++; V(w

文档评论(0)

1亿VIP精品文档

相关文档