|
| samguddy (6) | |
| Hey Guys, Let me begin by saying thanks. You guys are really helpful. My problem is that I have to write a program creating 5 readers and 3 writer processes. I have to use counting & binary semaphore to prevent readers and writers in the critical section at the same time. I have the code for using the reader and writers semaphore but I've never created a new process or critical section. What I have done is create multiple threads which was easy. Can you guys guide me in the right direction. Thanks In Advance. Samguddy | |
| j1230xz (10) | ||
Do you mean
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 | ||
This topic is archived - New replies not allowed.
