Skip to content

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

@taiki-e

Description

@taiki-e

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: A new feature or an improvement for an existing one

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions