3 ms·
> you could possibly do away atomics, since (I believe) int updates are atomic by default. The release can be a compiler only barrier followed by a simple stor
by gpderetta 7y ago
> you could possibly do away atomics, since (I believe) int updates are atomic by default.
The release can be a compiler only barrier followed by a simple store, but you do need an atomic RMW in the acquire path.
It is technically possible to implement a lock with just loads and stores (see Peterson lock[1]) even in the acquire path but it does require a #StoreLoad memory barrier even on Intel, which is as expensive as an atomic RMW so it is not worth it.
Edit:fixed barrier name typo.
[1] https://en.m.wikipedia.org/wiki/Peterson%27s_algorithm https://en.m.wikipedia.org/wiki/Peterson%27s_algorithm
- temac 7y ago> #StoreRelease memory barrier even on Intel What is that? x86 is TSO... Do you have an example of the full acquire and release sections in x86 assembly?
- gpderetta 7y agoI'm sorry, I meant #StoreLoad. Edit: here is a good (but long) article with a x86 Peterson Lock example (with an analysis of the critical race without the barrier): https://bartoszmilewski.com/2008/11/05/who-ordered-memory-fences-on-an-x86/ https://bartoszmilewski.com/2008/11/05/who-ordered-memory-fe...