Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The best part is that the original code is not safe even on x86 as the compiler can still reorder non-volatile accesses to the backing_buf around the volatile accesses to head and tails. Compiler barriers before the volatile stores and after volatile reads are required [1]. It would still be very questionable code, but it would at least have a chance to work on its intended target.

tl;dr: just use std::atomic.

[1] it is of course possible they are actually present in the original code and just omitted from the explanation for brevity



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: