[Info-vax] Volatile, was: Re: yet another sys$qiow question
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Thu Aug 20 12:12:17 EDT 2015
On 2015-08-20, JF Mezei <jfmezei.spamnot at vaxination.ca> wrote:
> On 15-08-20 11:19, John Reagan wrote:
>
>> Correct. If all you do is declare the IOSB, pass it to $QIO and don't read it until the EF or AST is delivered, the lack of volatile is probably not important.
>
> Say I set the IOSB to zeroes,
> call QIOW passing IOSB
> then check IOSB to make sure IO completed with success.
>
> Would the compiler realise that QIOW could modify the IOSB and thus make
> sure that when I check the IOSB, it doesn't assume it is still set to 0s ?
>
Will yes, that's how all compilers work because sys$qiow doesn't return
control back to the program until it's completed so it's just like a
normal subroutine call.
> So, if I use QIO instead of QIOW, wouldn't the compiler also flag IOSB
> as potentially having been modified, so the next time it is read, it
> needs to be read from memory ?
>
Once again, the potential problem is not when the QIO is queued, but when
it completes.
There's nothing in the C language standards that talks about the system
call known as sys$qio on the operating system known as VMS.
What there are is a set of rules which talk about C in general and what
a compiler is and is not allowed to do. The compiler does not have any
knowledge that this specific routine called sys$qio can have program
visible side effects at some random point later on in time.
There are also a set of rules which the programmer is expected to follow.
One of these rules says that you have to tell the compiler if you have
data whose contents can suddenly change within the middle of a block
without any action on the part of the program within that block.
If you don't follow this rule, the compiler is allowed to assume that
this data will be static during the lifetime of this block and is allowed
to generate code accordingly.
>
> I realise that once in a loop that checks IOSB, the compiler wouldn't
> see any other potential modification of IOSB within the loop and
> optimize it away.
>
That position (which actually reflects the current reality with the
appropriate compiler and the appropriate optimiser settings) is
incompatible with the question in your previous paragraph. :-)
Simon.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list