On 30/03/2015 19:04, Dr. David Alan Gilbert wrote: >>> > > That one's a trickier question. Compilers are absolutely capable >>> > > of optimizing that far, *but* the C rules about when it's allowed >>> > > to assume in-memory values remain unchanged are pretty >>> > > conservative. I think any function call in the loop will require >>> > > it to reload the value, for example. That said, a (compiler only) >>> > > memory barrier might be appropriate to ensure that reload. >> > >> > That's exactly what atomic_read provides. > So does that say I need the atomic_read but not the atomic_write - > which seems a bit weird, but I think only due to the naming.
No, you need both even though it's even more far-fetched that the compiler will do something bad with the set. Paolo