Skip to content

add AtomicOption#186

Closed
programmerjake wants to merge 1 commit into
crossbeam-rs:masterfrom
programmerjake:atomic_option
Closed

add AtomicOption#186
programmerjake wants to merge 1 commit into
crossbeam-rs:masterfrom
programmerjake:atomic_option

Conversation

@programmerjake
Copy link
Copy Markdown

Add AtomicOption, an atomic version of Option<ReferenceLike<T>> where ReferenceLike<T> is Box<T>, Arc<T>, &T, and &mut T for now -- basically anything that has a lay-out like NonNull<T>.

I didn't implement AtomicOption<NonNull<T>> for now as NonNull<T> is not Send so AtomicOption is mostly useless for that case.

@ghost
Copy link
Copy Markdown

ghost commented Sep 1, 2018

Hi @programmerjake, and thanks for the pull request! :)

We've recently added AtomicCell to crossbeam-utils, which is very similar to AtomicOption and more general. For example, the equivalent of AtomicOption<Box<T>> would be AtomicCell<Option<Box<T>>>.

See crossbeam-rs/crossbeam-utils#13 and crossbeam-rs/crossbeam-utils#39 for more details.

Instead of adding AtomicOption, we should just publish a new version of crossbeam-utils and then reexport AtomicCell in crossbeam.

What do you think - does AtomicCell have everything you need from it?

@programmerjake
Copy link
Copy Markdown
Author

AtomicCell seems satisfactory. I do think it would be nice to add methods to AtomicCell that allow use of more relaxed atomics:

  • Ordering::AcqRel should be fine from safe code as that's what Mutex provides.
  • weaker orderings would be nice to have but they would be unsafe unless you can prove that the data doesn't contain any references or pointers, maybe using an auto trait to require that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant