User: Password:
|
|
Subscribe / Log in / New account

Declaring it volatile

Declaring it volatile

Posted Aug 6, 2012 23:12 UTC (Mon) by PaulMcKenney (subscriber, #9624)
In reply to: Declaring it volatile by daglwn
Parent article: ACCESS_ONCE()

Sorry, but it is still not clear to me, especially your point about explicitness. After all, one of the advantages of the ACCESS_ONCE() approach is that lockless accesses are very clearly and explicitly flagged.


(Log in to post comments)

Declaring it volatile

Posted Aug 7, 2012 3:42 UTC (Tue) by daglwn (guest, #65432) [Link]

No, ACCESS_ONCE explicitly flags "volatile" accesses. That is, one has to explicitly use it to guarantee safety. That's an invitation for bugs.

Declaring it volatile

Posted Aug 7, 2012 14:37 UTC (Tue) by PaulMcKenney (subscriber, #9624) [Link]

And one of the corresponding bugs for your suggested approach of marking the variable volatile and caching the value in a temporary is failure to update the temporary when updating the underlying variable. So I remain unconvinced.

Declaring it volatile

Posted Aug 7, 2012 19:44 UTC (Tue) by daglwn (guest, #65432) [Link]

If the programmmer is optimizing by using a temporary, the assumption is that the programmer knows what he or she is doing. The optimization is explicit and is an immediate flag to the reader to carefully examine the (existing or new) code for bugs.

I'm not trying to convince you, simply stating what I believe is good programming practice. Maybe I'm wrong. But it's worked for me so far. :)

Declaring it volatile

Posted Aug 8, 2012 15:26 UTC (Wed) by PaulMcKenney (subscriber, #9624) [Link]

To each their own, I guess.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds