Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Write locks #105

Open
maleet opened this issue Mar 26, 2024 · 3 comments
Open

Read Write locks #105

maleet opened this issue Mar 26, 2024 · 3 comments

Comments

@maleet
Copy link

maleet commented Mar 26, 2024

Could read lock also be implemented?

For now I use ReaderWriterLockSlim for this and for key based access I added dictinoary to hold instances... keyed-semaphore already have this for write part... If only many-reads part could be added here... :)

@amoerie
Copy link
Owner

amoerie commented Mar 27, 2024

Interesting proposition, if I understand correctly you basically need the same concurrent bookkeeping this library already has, but with keys mapped to a ReaderWriterLockSlim. Then you would probably want methods like LockRead or LockWrite.

I would definitely be willing to help and review this KeyedReaderWriterLocks you have in mind, but I hope you understand I won't take the time to implement all of this myself.

@maleet
Copy link
Author

maleet commented Mar 27, 2024

Yes exactly. There are also some methods for upgradeable read...

Usage for me is in cache implementation, where there are many reads and if update, delete, reset occurs then all reads should be locked until operation is done. For upgrade... if first read will trigger cache initialization then I should switch to write and all other reads should wait until it's initialized. For keyed part... there are many caches and all these should have their own instances of locks.

Currently in this lib all locks are write locks so if there is lock then all others are in waiting list. Looks like methods for Read (and upgradeable read) should be added. But I understand this part can be PR for this lib and I can be author for that :)

@amoerie
Copy link
Owner

amoerie commented Mar 27, 2024

Sounds good! If you set up an initial PR we can work from there. I would like to keep the changes to the existing code as minimal as possible by the way, because I'm running a bunch of mission critical software with it. But we can see where this leads. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants