semaphore readMutex=1
semaphore writeMutex=1
semaphore allowOneReader=1
int readcount=0
int writecount=0
semaphore readMain=1
semaphore writeMain=1
Reader protocol to read
allowOneReader.wait( );
readMain.wait();
readMutex.wait();
readcount++;
if ( readcount == 1 )
writeMain.wait();
readMutex.signal();
readMain.signal();
allowOnereader.signal();
<reader critical section>.
readMutex.wait();
readcount--;
if ( readcount == 0 )
writeMain.signal();
readMutex.signal();
Writer protocol to write
writeMuex.wait();
writecount++;
if ( writecount == 1 )
readMain.wait();
wrietMutex.signal();
writeMain.wait();
<writer critical section>;
wrietMain.signal();
wrietMutex.wait();
writecount--;
if ( writecount == 0 )
readMain.signal();
writeMuex.signal();
What is this post for? Windows or Linux? Well nice blog for tech people.. Keep it up..
ReplyDeletewww.ItsMyCountdown.com, www.Nilabh.in, www.DharmSansar.com
This has nothing to do with Windows or Linux?
ReplyDeleteThis is general OS concept applicable to any OS.
Are you publishing ur website?