Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

atomic ops using compiler intrinsics are not safe #76

@bremoran

Description

@bremoran

armcc documentation says this:

10.139 __strex intrinsic
Note
The compiler does not guarantee to preserve the state of the exclusive monitor. It might generate load and store instructions between the LDREX instruction generated for the __ldrex intrinsic and the STREX instruction generated for the __strex intrinsic. Because memory accesses can clear the exclusive monitor, code using the __ldrex and __strex intrinsics can have unexpected behavior. Where LDREX and STREX instructions are needed, ARM recommends using embedded assembly.

@mjs-arm assures me that gcc could potentially reorder around our use of __LDREX and __STREX as well.

We should use gcc's atomic intrinsics for gcc targets. Of particular interest are:

  • __atomic_compare_exchange
  • __atomic_add_fetch
  • __atomic_sub_fetch

cc @bogdanm @mjs-arm @rgrover

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions