int readcount=0; //读进程计数semaphore writeblock,mutex;writeblock=1;mutex=1;cobegin process reader_i(){ process writer_j(){P(mutex); P(writeblock);readcount++; {写文件};if(readcount==1) V(writeblock);P(writeblock); }V(mutex);{读文件};P(mutex);readcoount--;if(readcount==0)V(writeblock);V(mutex);}coend 查看原帖>>
满意请采纳