Skip to content
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

Consider providing fallback implementation that uses lock per atomic type #32

Open
taiki-e opened this issue Aug 13, 2022 · 1 comment
Labels
C-enhancement Category: A new feature or an improvement for an existing one

Comments

@taiki-e
Copy link
Owner

taiki-e commented Aug 13, 2022

The current lock-based fallback uses global locking for memory layout compatibility with standard library atomic types. This is the approach also used in C++ std::atomic, atomic-rs, and crossbeam AtomicCell, which is not so bad, but not best from a point of view of performance.

// Fallback implementation using global locks.
//
// This implementation uses seqlock for global locks.
//
// This is basically based on global locks in crossbeam-utils's `AtomicCell`,
// but seqlock is implemented in a way that does not depend on UB
// (see comments in optimistic_read method in atomic! macro for details).
//
// Note that we cannot use a lock per atomic type, since the in-memory representation of the atomic
// type and the value type must be the same.

It may be possible to provide something like this as a parameter or from another module.

@taiki-e taiki-e added C-enhancement Category: A new feature or an improvement for an existing one C-question Category: A question labels Aug 13, 2022
@taiki-e
Copy link
Owner Author

taiki-e commented Aug 13, 2022

Alternatively, we might want to allow custom fallback implementation.

@taiki-e taiki-e removed the C-question Category: A question label Aug 13, 2022
@taiki-e taiki-e added the A-portable-atomic-util Area: related to portable-atomic-util crate label Jan 12, 2023
@taiki-e taiki-e removed the A-portable-atomic-util Area: related to portable-atomic-util crate label Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A new feature or an improvement for an existing one
Projects
None yet
Development

No branches or pull requests

1 participant