读写信号量

读写信号量,读写互斥,可以多读

seg R, W;
int read_count=0;

void read()
{
   P(R);
   if(read_count==0)
   {
       P(W);
   }  
   read_count++;
   V(R);
  
   reading...

   P(R);
   read_count--;
   if(read_count==0)
   {
      V(W);
   }
   V(R);
}

void write()
{
    P(W);
    writing...
    V(W);
}
原文地址:https://www.cnblogs.com/reach/p/3365927.html