On 11/2/2017 9:07 AM, Sebastian Andrzej Siewior wrote:
Why so? There is no way the compiler could have cached the value somehow.
Well, I think it would be sufficient to notice that the code you were replacing used a READ_ONCE and you're putting it into a function that's a bit more complicated. But I'd suggest you read [1] which essentially says that all shared variables should be accessed with such a macro even if only to document that it's a part of a thread synchronization protocol.
Logan [1] https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE