Skip to content

Volatile might not be the best (or even right) implementation for atomics #4700

@josephnoir

Description

@josephnoir

As discussed in #4583 this is a separate issue and needs its own thread. The original source for this consideration was a problem with static initialization of structs containing non-literal members (e.g., ones with volatile) in C++.

However, during the following discussion it was questioned if volatile is the right way to implement atomic integers. Here are some of our sources:

And some posts on Stack Overflow:

And related Wikipedia entires:

My current understanding is that memory barriers would be preferable to volatile. However, there are different barriers (compiler and hardware), which prevent memory reordering at different points. ARM architectures seem to have different reordering strategies than x86 ones.

Hardware memory barriers:

Two questions:

  • Would an implementation without volatile be preferable?
  • What would it look like?

Metadata

Metadata

Assignees

Labels

Area: coreArea: RIOT kernel. Handle PRs marked with this with care!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions