Skip to content

Featue: making len atomic #8

@cehteh

Description

@cehteh

I would like to know if you are interested to merge a rather big slightly breaking change:

The .len field could be atomic with:

  • add unsafe fn HeaderVecHeader::len_add_release() incrementing the length being a atomic op
    This is unsafe because one has to hold a promised contract, see below
  • making HeaderVecHeader::len(&mut self) -> usize (note the mut, this is a breaking change)
  • adding unsafe fn HeaderVecHeader::len_acquire(&self) -> usize this is what .len() currently does, but using atomics

Alternative without breaking changes:

  • using the atomic op for .len(&self) under the hood, keeping the compatible API
  • adding a HeaderVecHeader::len_noatomic(&mut self) -> usize // or other name
    Disadvantage is that the .len() API which is what users most likely want to use/expect would have to pay the atomics cost on some platforms.

Rationale:
One can add elements within capacity and then when done increment the len atomically as long the vec stays within capacity. But adding elements needs some synchronization otherwise this will be racy. The len_add_release() is unsafe because of this. The actual synchronization is deliberately not part of the implementation here and has to be done somehow else.

Currently I roll my own allocation very similar to what this crate does in https://crates.io/crates/cowstr I would like to externalize this to another crate and yours fits my needs except for the above changes. When you like the idea I will make the proposed changes and send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions