4 ms·
> You can't fix it with barriers. You need a lock or LL/SC loop. Agreed on this point. > No, they can't (without widening char to 32 bits). The code you have
by dragontamer 7y ago
> You can't fix it with barriers. You need a lock or LL/SC loop.
Agreed on this point.
> No, they can't (without widening char to 32 bits). The code you have shown modifies the adjacent elements. Anyone that write a nearby byte in the window between the load and the store will have their write silently clobbered.
I guess my misunderstanding was that C++11 gave this guarantee. That's pretty cool.
I guess I typically expected specific bitwise operators (ex: atomic_and or atomic_or) to be necessary in these cases. But if DEC Alpha is really the only processor in (somewhat) recent memory that doesn't allow 8-bit granularity, then it makes sense to just standardize upon 8-bit granular reads/writes.
- BeeOnRope 7y agoI would be very hard to write correct software involving threads without that guarantee. Most threaded programs are using lots of private data, and imagine if another thread could just randomly stop on your private data while it was trying to do a nearby write? Maybe you could try to formalize the idea of "keep private data away from data on other threads" or something, but this seems very difficult (in practice, private data is private as an emergent property of the whole application, so is not easily identifiable), and you'd have to give up on a lot of things the existing model offers in terms of write-independence.