logoalt Hacker News

SR2Zyesterday at 7:41 PM1 replyview on HN

Isn't the point of using atomics that there is virtually no performance penalty in single threaded contexts?

IMO "zero cost abstraction" just means "I have a slightly less vague idea of what this will compile to."


Replies

SkiFire13yesterday at 7:46 PM

No, atomics do have a performance penality compared to the equivalent single threaded code due to having to fetch/flush the impacted cache lines in the eventuality that another thread is trying to atomically read/write the same memory location at the same time.

show 1 reply