Skip to content

Fix inaccurate Always_Terminates aspect on atomic operations - #30

Merged
damaki merged 1 commit into
mainfrom
topic/atomic-exchange-termination
Jun 15, 2026
Merged

Fix inaccurate Always_Terminates aspect on atomic operations#30
damaki merged 1 commit into
mainfrom
topic/atomic-exchange-termination

Conversation

@damaki

@damaki damaki commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Atomic exchange intrinsics are used in package LibSAP.Pointer_Holders, and Always_Terminates was specified for these operations. This is inaccurate, however, since atomic exchange is not guaranteed to terminate on all target architectures.

For example, on Armv7-M, the compiler emits LDREX and STREX instructions in a loop to implement atomic exchange. Such a loop is not guaranteed to terminate as it may experience a livelock or infinite retry loops. In practice this should not happen, but the worst case must be specified for the termination proofs to be correct.

Atomic exchange intrinsics are used in package LibSAP.Pointer_Holders,
and Always_Terminates was specified for these operations. This is inaccurate,
however, since atomic exchange is not guaranteed to terminate on all
target architectures.

For example, on Armv7-M, the compiler emits LDREX and STREX instructions in a
loop to implement atomic exchange. Such a loop is not guaranteed to terminate
as it may experience a livelock or infinite retry loops. In practice this
should not happen, but the worst case must be specified for the termination
proofs to be correct.
@damaki damaki self-assigned this Jun 15, 2026
@damaki damaki added the enhancement New feature or request label Jun 15, 2026
@damaki
damaki merged commit 29e31e9 into main Jun 15, 2026
9 checks passed
@damaki
damaki deleted the topic/atomic-exchange-termination branch June 15, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant