|
How to solve First Readers Writers problem using semaphores?
int rcount; semaphore a=1;wrt=1; void reader() { while(true) { Wait(a); rcount++; if(rcount==1) Wait(wrt); Signal(a); READ_DATABASE(); Wait(a); rcount --; if(rcount==0) Signal(wrt); Signal(a); } } void writer() { while(true) { Wait(wrt); WRITE_DATABSE(); Signal(wrt); } } ------------------------ main() // main program { rcount=0; parbegin (reader, writer); }
Your Answer
DISCLAIMER
Paked and the contributors are not responsible for any errors contained and are
not liable for any damages resulting from the use of this material.
Disclaimer
|
|