这是第一个读者/作者问题的代码:
semaphore wrt=1, mutex=1;
readcount=0;
writer()
{
wait(wrt);
// Writing is done
signal(wrt);
}
reader()
{
wait(mutex);
readcount++;
if (readcount == 1)
wait(wrt);
signal(mutex);
// Do the Reading
// (Critical Section Area)
wait(mutex);
readcount--;
if (readcount == 0)
signal(wrt);
signal(mutex);
}
我不明白的是reader() 函数中wait(wrt)
and的使用。signal(wrt)
你能解释一下吗?