arcstr icon indicating copy to clipboard operation
arcstr copied to clipboard

Atomic swap?

Open SOF3 opened this issue 4 years ago • 6 comments

I would like to update an ArcStr atomically. Is it possible to implement some wrapper like arc_swap for arcstr, or must that introduce significant overhead?

SOF3 avatar Aug 07 '21 15:08 SOF3

It seems that we can make arcstr have an optional feature arc-swap that implements the arc_swap::RefCnt trait, and ArcSwapAny<ArcStr> can immediately work.

I can try to implement this if the proposal is approved.

SOF3 avatar Aug 07 '21 15:08 SOF3

Yeah, that would be fine, since they seem fairly semver-stable. If there are issues I can take a stab at it as well.

thomcc avatar Aug 07 '21 17:08 thomcc

The feature should be called arc_swap though, e.g. it should just be

[dependencies]
arc_swap = { version = "1", optional = true }

Also you should note in the docs for this feature it should mention that turning this feature on requires libstd (arc_swap is not no_std).

thomcc avatar Aug 07 '21 17:08 thomcc

The package name is arc-swap nor arc_swap.

SOF3 avatar Aug 08 '21 09:08 SOF3

Sorry, it appears that arc-swap does not really support fat pointers, and using ArcSwapAny<ArcStr> is not really fasible.

SOF3 avatar Aug 08 '21 09:08 SOF3

Sorry, it appears that arc-swap does not really support fat pointers, and using ArcSwapAny<ArcStr> is not really fasible.

Hm, Worth noting that only the pointee is fat, ArcStr itself is not. But maybe they don't handle that possibility.

When I have time I'll read up on the algorithm and see if its feasible to implement a less-involved version (likely less performant too, unless the fact that we have no weak or mutable data can be leveraged) of it behind a feature or something.

thomcc avatar Aug 08 '21 17:08 thomcc