-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extended atomic types #13
Comments
I think the proposed nomenclature is more consistent than that of the current implementation. May I ask why Also, I wonder what will be the relation of |
Well, atomic We could have the whole palette of Yeah, I was thinking of subsuming the functionality of |
I wonder if we can efficiently implement |
// Accepts only `T: Sized`, pointers to which always fit into a single word.
struct AtomicBox<T> { inner: AtomicPtr<T> }
// Also accepts `T: !Sized`, pointers to which are fat (two words).
// We would need advanced specialization for this (not yet implemented).
struct AtomicBox<T: ?Sized> { inner: ??? } I don't think we can easily support fat pointers at all, at least not until full specialization gets into Rust. |
AtomicArc and AtomicBox should probably support Option, even if the name desn't say so 👍 I don't have a strong opinion on supporting arbitrary sized stuff (?Sized and AtomicCell). |
Another primitive we might want is something like Pinboard. This is basically just an epoch-protected impl<T: Send + 'static> EpochBox<T> {
fn new(t: T) -> Self;
fn remove(&self);
fn set(&self, t: T);
}
impl<T: Send + Sync + 'static> EpochBox<T> {
fn get<'scope>(&self, scope: &'scope Scope) -> Option<&'scope T>;
fn take<'scope>(&self, scope: &'scope Scope) -> Option<&'scope T>;
fn swap<'scope>(&self, t: T, scope: &'scope Scope) -> Option<&'scope T>;
}
impl<T: Send + Sync + Clone + 'static> EpochBox<T> {
fn get_clone(&self) -> Option<T>;
fn take_clone(&self) -> Option<T>;
fn swap_clone(&self, t: T) -> Option<T>;
} |
EpochArc also works well. |
To my eyes, crossbeam-rs/crossbeam-utils#2 suggests that we should not allow users to specify For |
@jeehoonkang Yeah, I'm thinking of |
You may want to have a look at this crate, which does exactly that. |
The disadvantage of using a mutex is that the crate won't work with |
What do folks think about supporting double-word atomics? |
@spacejam It should be exposed as |
@Amanieu in particular I'm interested in dw cas that runs on ARM 32 (6k+) for the equivalent of AtomicU64 so that sled can easily support that architecture. |
|
@spacejam I'm also waiting for DWCAS to land in Rust. It will enable a whole new class of concurrent algorithms, e.g. LCRQ for starters. It was not possible even in C++, as DWCAS is not supported in its standard library! |
@jeehoonkang there is a bunch of code I'm looking forward to refactoring once DWCAS is available! Super excited for it :) |
@jeehoonkang DWCAS is supported in C++ through the generic |
The standard library offers several primitive atomic types:
Atomic{Usize,Isize,Bool,Ptr}
. Nightly Rust also hasAtomic{U8,I8,U16,I16,U32,I32,U64,I64}
.Those are the primitive types, and then there are crates that expand a little bit. Crate
atomic
has typeAtomic<T>
whereT
can be any type (smallT
s that areCopy
use primitive atomics, and large or non-Copy
T
s simply get wrapped in a mutex).crossbeam
hasAtomicOption<T>
(atomicOption<Box<T>>
) andArcCell<T>
(atomicArc<T>
). There's also crateatomic-option
with a wider set of methods onAtomicOption<T>
.Taking a step back, I'd summarize and rename all those extended atomic types like this:
AtomicBox<T>
- atomicOption<Box<T>>
(equivalentAtomicOption<T>
)AtomicArc<T>
- atomicOption<Arc<T>>
(similar toArcCell<T>
)AtomicCell<T>
- atomicCell<T>
(equivalent toAtomic<T>
)What do you think about including such
AtomicBox<T>
,AtomicArc<T>
, andAtomicCell<T>
in Crossbeam?What I'm attempting to do here is to come up with a well-thought-out set of complementary atomic types that is a natural extension to the primitve atomic types in the standard library. Any thoughts or ideas? Any other nice-to-have atomic types I'm missing?
The text was updated successfully, but these errors were encountered: