Do you mean
5 readers and 3 writer processes |
or maybe threads. Since critical section cannot prevent other processes to enter it. It is used for thread synchronization not process synchronization. You would need to use mutexes or semaphores depending your need.
This is a link that can help you distinguish between mutexes and semaphores
http://koti.mbnet.fi/niclasw/MutexSemaphore.html
One suggestion for your idea:
i guess you want readers to execute separately from the writers
The given solution only takes into account when it is legal for all readers to execute simultaneously and all writers to execute simultaneously and only not to mix them:
reader and writer together.
- create 2 semaphores (one for read one for write operation)
in the readers:
- wait for write semaphore (we need 0)
- increment read semaphore
- perform reading
- decrement read semaphore
in the writers:
- wait for read semaphore (we need 0)
- increment write semaphore
- perform writing
- decrement write semaphore
This way you can make sure that when readers are running the writers will wait and vice versa