Skip to content

Immutable-only value access #292

@AshleySchaeffer

Description

@AshleySchaeffer

Hello, this is definitely related to issue #169 . Sorry to reignite the debate in a new issue, but I'm less precious about the implementation (i.e. it can be part of the entry API). I am seeking a method that returns immutable references to the new value (Ref, not RefMut) after an insert.

As stated in the linked issue, both Entry enum variants use mutable references which, as you likely know, means other threads attempting to access the key must wait until the mutable reference is dropped. In a hot code path this would mean both read and write operations from other threads may cause contention. I believe this works perfectly well for cases where dashmap is the sole provider of shared mutability of values.

However, if the value type of a dashmap handles shared mutability itself, the caller would only need immutable references to it. In essence, I want to rely on dashmap for the coordination of insertion and deletion, but have the freedom to choose how I coordinate mutable access to the value. At present immutable access to a key can not be avoided where the code "gets or inserts" keys.

As a suggestion, could the entry API be duplicated to make entry and entry_mut, where the latter is the current entry API and the former is a duplicate that utilises a EntryRead type that provides only a read guard? The downside is that this would be a breaking change of entry API users, in favour of a more common naming convention. Alternatively, perhaps entry_read could be added leaving the existing entry API as it is today.

Thanks for your time and amazing work <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions