3 ms·
Relaxed is useful when you need atomicity but not consistency between cores. x86 guarantees that all reads/writes are atomic, i.e. no torn reads/writes but I do
by en4bz 11y ago
Relaxed is useful when you need atomicity but not consistency between cores. x86 guarantees that all reads/writes are atomic, i.e. no torn reads/writes but I don't think all architectures have this guarantee.
Also there maybe times in your program where you know that your thread has exclusive access to the variable during a certain segment of the program. During this segment it may be beneficial to do lazy reads/writes then complete the critical section with a release operation.
This is used heavily in single producer single consumer queues.
- PeCaN 11y agoMinor nitpick, but x86 only guarantees atomic reads/writes for properly aligned values. I believe ARM is the same, but not very sure about that.