信号量:mutex=1;
write=1;
int count=0;
Main()
{
Cobegin:
Reader();
Writer();
Coend;
}
Reader()
{
while(true)
{
P(mutex);
if(count==0)
P(write);
count++;
V(mutex);
P(mutex);
count--;
if(count==0)
V(write);
V(mutex);
}
}
Writer()
{
while(true)
{
P(write);
写文件
V(write);
}
}