alloc::sync::Arc for core

EDITED

Hi there,

I was wondering if there was an appetite for alloc::sync::Arc/Weak being made available to core?

Previous discussions: Rename ARC to AtomicRc, move to core::unstable::sync · Issue #6652 · rust-lang/rust · GitHub. However, I'm wondering if those discussions occurred at a time where atomics wasn't available to core (unsure even if that was ever a situation).

Kind regards, Christopher

It's first defined as alloc::sync::Arc, if you're just looking for a no_std solution.

1 Like

Thank you - I missed that!

What is your goal in moving from alloc to core?

Sorry, I forgot about alloc and its availability to nostd. Using Arc with nostd is my goal.

It certainly would be nice to have something that can abstract out the reference-counting part of Arc into core. This code turns out to be extremely subtle and, personally, it's a pain to have to re-implement while being careful to insert the right release fences around destructors... basically I want core::sync::atomic::AtomicCounter that lets you manually increment or decrement the strong/weak counts and perhaps has some hook for "please run this cleanup code if the strong count is zero in an appropriately-fenced manner".

Hmm, maybe worth writing a crate that rips the relevant bits out of Arc...

3 Likes