User: Password:
Subscribe / Log in / New account

Declaring it volatile

Declaring it volatile

Posted Aug 3, 2012 18:04 UTC (Fri) by BenHutchings (subscriber, #37955)
In reply to: Declaring it volatile by corbet
Parent article: ACCESS_ONCE()

Also, implicit access-once behaviour can make it harder to understand how the code works.

(Log in to post comments)

Declaring it volatile

Posted Jan 30, 2014 22:39 UTC (Thu) by timur (guest, #30718) [Link]

The functionality of this macro is actually well described by its name

I disagree. I was completely confused by the article until I saw the implementation of ACCESS_ONCE, because the behavior being described is the opposite of what I think "access once" means. ACCESS_ONCE makes me believe that that it operates like pr_info_once(), which literally calls pr_info only once, no matter how many times loop repeats. I also don't see how declaring it volatile forces the compiler to reload the variable only at the top of the loop. Since it's declared volatile, the compiler can reload 'owner' any time it wants.

Declaring it volatile

Posted Jan 30, 2014 22:55 UTC (Thu) by timur (guest, #30718) [Link]

Hmm ... I think I get it. Since lock->owner is temporarily declared volatile, the compiler forces a load at that point in the code. But 'owner' is not declared volatile, so the compiler doesn't need to reload it, and it has "forgotten" about lock->owner, so it never tries to reload it, until the loop restarts.


Declaring it volatile

Posted Jan 31, 2014 4:07 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

Maybe a better name would be FORCE_ACCESS_HERE().

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