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

APIs for mutable (exclusive) access #39

Open
hawkw opened this issue Apr 4, 2020 · 1 comment
Open

APIs for mutable (exclusive) access #39

hawkw opened this issue Apr 4, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@hawkw
Copy link
Owner

hawkw commented Apr 4, 2020

In some cases, entries will not be accessed concurrently. It might be nice to have an API for mutably accessing an entry by index if it is not being concurrently accessed. This would need to ensure that the reference count is 0, and (probably) set a bit in the slot's lifecycle to that prevents immutable access while the slot is accessed mutably.

If the slot is already mutably accessed, we would want to return None or an AlreadyAccessed error of some kind (so that users can distinguish between cases where a slot cannot be referenced mutably, and cases where the slot does not exist). We probably don't want to have a method that spins until the slot can be accessed mutably — if users want to block the calling thread, they'd be better off using a read-write lock.

@hawkw
Copy link
Owner Author

hawkw commented Apr 4, 2020

If we did this, we could consider also having the create API return the mutable guard rather than taking a closure. When the slot has been mutated, the guard can be "downgraded" or dropped to release it for other threads to borrow immutably.

@hawkw hawkw added the enhancement New feature or request label Apr 4, 2020
@hawkw hawkw self-assigned this Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant