Skip to content

add AtomicOption #186

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

Closed

Conversation

programmerjake
Copy link

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

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
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