logoalt Hacker News

kristianpyesterday at 7:05 PM5 repliesview on HN

This is in C++, other languages have different atomic primitives.


Replies

smj-edisontoday at 2:39 PM

Don't most people use C++11 atomics now? You have SeqCst, Release, Acquire, and Relaxed (with Consume deprecated due to the difficulty of implementing it). You can do loads, stores, and exchanges with each ordering type. Zig, Rust, and C all use the same orderings. I guess Java has its own memory model since it's been around a lot longer, but most people have standardized around C++'s design.

Which is a slight shame since Load-Linked/Store-Conditional is pretty cool, but I guess that's limited to ARM anyways, and now they've added extensions for CAS due to speed.

show 2 replies
jitltoday at 1:58 PM

Really? Pretty much all atomics i’ve used have load, store of various integer sizes. I wrote a ring buffer in Go that’s very similar to the final design here using similar atomics.

https://pkg.go.dev/sync/atomic#Int64

show 2 replies
blackliontoday at 3:04 PM

JVM has almost the same (C++ memory model was modeled after JVM one, with some subtle fixes).

dalvrosayesterday at 9:51 PM

Yeah, this is quite specific to C++ (at a syntax level)

amlutotoday at 2:16 PM

Huh? Other languages that compile to machine code and offer control over struct layout and access to the machine’s atomic will work the same way.

Sure, C++ has a particular way of describing atomics in a cross-platform way, but the actual hardware operations are not specific to the language.

show 1 reply