Explain and write the code for Concurrent Read, Exclusive Writer
semaphore mutex=1,wrt=1;
int readcount=0;
reader process:
{{{
wait(mutex);
readcount++;
if(readcount==1)
wait(wrt);
signal(mutex);
…
reading is performed
…
wait(mutex);
readcount--;
if(readcount==0)
signal(wrt);
signal(mutex);
}}}
writer process:
{{{
wait(wrt)
…
writing is performed
…
signal(wrt);
}}}
At one time, one or more reader processes can share the data, but at one time only one writer can access the data. Mutex used to update the readcount, wrt used to implement exclusive accessing of writer
Wait() //increment
Signal() //decrement
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment