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

How to fail to acquire write lock if read lock already acquired? #436

Open
shivam-880 opened this issue Apr 15, 2024 · 2 comments
Open

How to fail to acquire write lock if read lock already acquired? #436

shivam-880 opened this issue Apr 15, 2024 · 2 comments

Comments

@shivam-880
Copy link

Is there a way for acquiring writer lock to fail if there is a reader lock already acquired but not if there is a write lock? What we really want is the ability to fail to acquire the write lock if read lock is already acquired instead of waiting for it!

@Amanieu
Copy link
Owner

Amanieu commented Apr 16, 2024

That's not possible: RwLock only tracks the number of readers so it doesn't know whether the current thread holds a read lock or not.

@shivam-880
Copy link
Author

No, what I meant was to fail acquiring write lock by any thread if any of the threads have a read lock ie., if read lock count > 1

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