用PV操作解决读者写者问题?拜托各位大神

2025-04-05 13:50:11
推荐回答(1个)
回答1:

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 查看原帖>>

满意请采纳