读者编写算法如何用于填充表格?

时间:2018-03-05 23:20:49

标签: algorithm operating-system

读者 - 作家问题

semaphore rw mutex = 1;
semaphore mutex = 1;
int read_count = 0;

Writer process:
do {
wait(rw_mutex);
                    . . .
         /* writing is performed */
                    . . .
signal(rw_mutex);
} while (true);

Reader process:
do {
   wait(mutex);
   read count++;
   if (read_count == 1)
       wait(rw mutex);
   signal(mutex);
                . . .
      /* reading is performed */
                . . .
   wait(mutex);
   read count--;
   if (read_count == 0)
       signal(rw_mutex);
   signal(mutex);
   } while (true);

填写信号量值

的表格
event                mutex    wrt    readcount 
a writer comes        1        0        0
a reader comes        1       -1        1
a writer has done     1        0        1
a reader comes        1        0        2
a reader comes        1        0        3
a writer comes        1       -1        3
a reader has done     1       -1        2  
a reader has done     1       -1        1
a reader has done     1        0        0
a writer comes        1       -1        0

这是我的解决方案,但这是错误的。有人可以让我明白我错在哪里以及它是如何运作的。

0 个答案:

没有答案