Skip to content

Conversation

@tokyovigilante
Copy link
Contributor

InterlockedCompareExchange64 (winnt.h) is used instead of gcc atomics when compiling with MSVC on Windows, but the function signatures are InterlockedCompareExchange64(ptr int64, int64, int64) and InterlockedCompareExchange32(ptr int32, int32, int32) as opposed to (ptr T, ptr T, T) for __atomic_compare_exchange_n.

Passing a pointer to the expected value (parameter two) instead of the value itself causes the comparison to unconditionally fail, with stalls in threaded code using atomic comparisons.

Fix the function signature for MSVC.

InterlockedCompareExchange64 (winnt.h) is used instead of gcc atomics
when compiling with MSVC on Windows, but the function signatures are
InterlockedCompareExchange64(ptr int64, int64, int64) and
InterlockedCompareExchange32(ptr int32, int32, int32) as opposed to
(ptr T, ptr T, T) for __atomic_compare_exchange_n.

Passing a pointer to the expected value instead of the value itself
causes the comparison to unconditionally fail, with stalls in threaded
code using atomic comparisons.

Fix the function signature for MSVC.

Signed-off-by: Ryan Walklin <[email protected]>
@ringabout ringabout merged commit 2d0b62a into nim-lang:devel Dec 2, 2025
18 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 2d0b62a

Hint: mm: orc; opt: speed; options: -d:release
190319 lines; 10.659s; 816.117MiB peakmem

narimiran pushed a commit that referenced this pull request Dec 2, 2025
`InterlockedCompareExchange64 `(winnt.h) is used instead of gcc atomics
when compiling with MSVC on Windows, but the function signatures are
`InterlockedCompareExchange64(ptr int64, int64, int64)` and
`InterlockedCompareExchange32(ptr int32, int32, int32)` as opposed to
`(ptr T, ptr T, T)` for `__atomic_compare_exchange_n`.

Passing a pointer to the expected value (parameter two) instead of the
value itself causes the comparison to unconditionally fail, with stalls
in threaded code using atomic comparisons.

Fix the function signature for MSVC.

Signed-off-by: Ryan Walklin <[email protected]>
(cherry picked from commit 2d0b62a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants