Open hawkw opened 4 years ago
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.
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 anAlreadyAccessed
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.