[Info-vax] Volatile, was: Re: yet another sys$qiow question
Stephen Hoffman
seaohveh at hoffmanlabs.invalid
Fri Aug 21 09:38:40 EDT 2015
On 2015-08-21 12:16:14 +0000, David Froble said:
> The problem arises when rather poor coding practice is used. I really
> would hope that none of the manuals or examples suggests reading the
> IOSB prior to the operation being signaled as complete.
>
> I understand what you're saying the volatile command does, but so far I
> don't think I've seen an example that needs it, except for what I'd
> consider improper coding.
I'm not entirely certain that the compilers will always do the right
thing here — always, and in the absence of a volatile declaration —
even when you're using what are currently considered proper coding
practices — there's definitely some code-smell here, and it may well be
the case that some compiler keeps the IOSB value in a register, meaning
that the out-of-band change to the IOSB is not made visible to the
application code.
The compiler has no insight into the asynchronous sharing of the IOSB
absent that volatile type, and accordingly the compiler might decide to
generate (entirely correct) code that keeps the IOSB value in a
register, once the data been read into the register from the IOSB.
I'd hope that a out-of-compilation-scope function call — such as a
system service call — that referencing the address of shared data would
force a re-load of the data into the register, but I don't know that.
Registers are valuable resources in present architectures, so the
generated code doesn't usually have a value sitting in a register for
very long. But register-caching is permissible in C and most other
languages, absent the language-specific asynchronous / volatile syntax.
This is analogous to the while-spin loop that has been posted here,
but it's a whole lot less visible.
--
Pure Personal Opinion | HoffmanLabs LLC
More information about the Info-vax
mailing list