[Info-vax] Volatile, was: Re: yet another sys$qiow question

Johnny Billquist bqt at softjar.se
Thu Aug 20 08:59:40 EDT 2015


On 2015-08-19 19:55, Jan-Erik Soderholm wrote:
> Den 2015-08-19 kl. 19:47, skrev John Reagan:
>> On Wednesday, August 19, 2015 at 12:58:05 PM UTC-4, VAXman- wrote:
>>> In article <>, Simon Clubley <> writes:
>>>> On 2015-08-19, VAXman-  @SendSpamHere.ORG <> wrote:
>>>>> Question:  If "volatile" is necessary, shouldn't this code keep
>>>>> spinning its tail???
>>>>>
>>>>
>>>> No, because you only have a function call in the loop (sys$qiow())
>>>> (and the function call additionally directly references iosb BTW).
>>>>
>>>> This means that regardless of whether the compiler terminates the
>>>> caching scope for iosb at any function call or whether it only
>>>> terminates the caching scope when a function call references iosb,
>>>> your code still causes the compiler to generate code to re-read the
>>>> current contents of the iosb variable after the function call
>>>> returns.
>>>>
>>>> The current discussion is based around the belief C compilers
>>>> terminate the caching scope at any function call. I don't know if
>>>> this is true for all the other languages VMS supports.
>>>
>>> So, I should put the $QIO in a subroutine.
>>>
>>
>> Well, the compiler saw that somebody took the address of the IOSB and
>> passed it along to $QIO.  The compiler doesn't know if that address was
>> saved in some global variable.  So the call to your jacket routine is
>> still probably sufficient to tell the compiler (this routine call might
>> write into every possible global variable and write into every variable
>> whose address was ever taken).
>>
>
> And what difference would that make? Would the compiler simply concider
> *everything* ("every variable whose address was ever taken) beeing
> "volatile"? Not particualy efficient...
>
> Isn't "volatile" just that, to hint the compiler about which variables
> that might change without a hint from the actual code compiled?

It's more than a "hint". Volatile tells the compiler that it is never 
allowed to optimize away any reads or writes the that variable in the 
code. They all need to be preserved, and the order of reads/writes also 
needs to be preserved.

	Johnny




More information about the Info-vax mailing list