Sunday 15 July 2012

unix - Multiple readers and multiple writers(i mean multiple) synchronization -


I am developing a feature that requires a version of the read / write lock that allows concurrent multiple authors Can allow.

Standard reading / writing lock allows multiple readers or single authors to run simultaneously. I need a version that can allow multiple readers or multiple authors simultaneously. Therefore, it should not allow a reader and author simultaneously. But, at the same time many authors are okay to allow many readers at the same time.

I hope I was clear. I could not find any existing algorithm yet. I can think of some ways to do this by using a few lines and etc. But, I do not want to take the risk of doing so myself unless someone is present.

Do you know about any existing scheme?

Thank you,

If you are using pthreads, the synchronization approach Take a look at the inside.

You can use a similar approach with two variables readerCount and writerCount and a mute x. In the reader thread, you will lock the Mute X and wait for writerCount == 0 . If this condition is completed, then you issue the lock by increasing the 1 readerCount . Then you read when you are done, then you lock Mute X again, reduce the readerCount , indicate the change in position and release the lock.

The author thread follows the same logic, but waits for the condition readerCount == 0 and instead the pay scale / decrease number of authors .

No comments:

Post a Comment