Implementing shared/exclusive locking (readers/writer) lock - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Implementing shared/exclusive locking (readers/writer) lock

Hi,
I am using semaphore to implement Single Writer Multiple Readers (Reader / writer) lock.
The problem is that semaphores are critical resources in linux systems, and there is a limit on the number of semaphores

that you can create.
So, after creating some semaphores, sometimes my application exceeds this limit, and I get an error like 'No space left on

device.'.

I have to reboot the system sometimes, to release the semaphores, if my application is terminated abruptly!

How should I implement readers/writers lock using something else than semaphore, which is scalable?

I don't need reader/writer locks across multiple processes. I just need to use them in multiple threads of my application,

which is a single process.
But I want a very scalable solution, say I want 500 locks through out my application daemon's lifetime.

I read in the link below that postgres also suffered the same problem, but there it is recommended that the limit should be

increased, which I don't want users to do.
[link=http://www2.units.it/~nircdc/doc/postgres/kernel-resources.html]http://www2.units.it/~nircdc/doc/postgres/kernel-resources.html[/link]
Sign In or Register to comment.