logoalt Hacker News

3836293648 • today at 1:57 AM • 4 replies • view on HN

As a part of the language? Are they really? You can do it all with library functions that just take regular int* (and so on).

Not that I'd want it, I like complex type systems, but I see it as philosophically consistent with C.


Replies

aw1621107 • today at 2:17 AM

> You can do it all with library functions that just take regular int* (and so on).

It's not just about atomics, but you might still find Hans Boehm's 2005 paper "Threads Cannot Be Implemented As a Library" [0] interesting. It describes (among other things) correctness and performance issues that can arise if the compiler and/or language don't know about thread/atomic semantics.

[0]: https://web.stanford.edu/class/archive/cs/cs240/cs240.1236/o...

➕ show 1 reply
jcranmer • today at 2:35 AM

Compilers have, for several decades now, stopped viewing optimization in terms of optimizing the instructions of a function and instead viewed it as preserving the semantics under some machine model. Consequently, it's rather important to actually nail down some of the object model semantics to be able to do things like understand which loads and stores actually need to be preserved, and you can't really do that with just library functions.

And, FWIW, in a lot of high-performance code, the overhead of a function call may be too high for an atomic operation.

publicmail • today at 2:08 AM

A library function written in what? Atomics also come along with memory ordering which isn’t otherwise expressible in the language, as in, there was no standard way to do a “load acquire” before, for example.

➕ show 1 reply
dokyun • today at 6:01 AM

Funny this is getting downvoted cause it's literally what Plan 9 C does.

https://man.cat-v.org/plan_9/2/atom

➕ show 1 reply