[Info-vax] yet another sys$qiow question
Johnny Billquist
bqt at softjar.se
Fri Aug 21 08:18:00 EDT 2015
On 2015-08-20 22:19, Craig A. Berry wrote:
> On 8/20/15 1:55 PM, Johnny Billquist wrote:
>> On 2015-08-20 16:42, Craig A. Berry wrote:
>
>>> I think the emphasis here should be on "poorly written program"; I
>>> certainly don't see any examples of what you're talking about in
>>> SYS$EXAMPLES and I don't see how anyone using the documented methods for
>>> making sure the I/O is complete before checking the IOSB would get into
>>> this kind of trouble.
>>
>> One example that I could think of, that might not be so poorly written
>> code, which could bite you, would be something like:
>>
>> SYS$QIO(<arguments>);
>> if (iosb == 0) {
>> <do some stuff>
>> <wait for I/O completion>
>> printf("IOSB is now %x\n", iosb);
>> }
>>
>> which would, with a good optimizing compiler, and iosb not declared as
>> volatile, an output showing that iosb was 0, even though it actually
>> would not be zero.
>
> Doubtful, because you would normally be passing the address of the IOSB
> to SYS$QIO, so the compiler would know that the world outside this
> routine may be modifying it.
Yes, you would definitely do that, and that was intended by the code.
And yes, the compiler knows the iosb might be modified. The point is,
the iosb is read *after* the call to SYS$QIO, at which point it will get
cached. That was my point in the code. Maybe you missed that?
: If it were while instead of if, then yes,
> the compiler might cache the value after the first read. But either way
> you are not checking for whether the I/O is complete *before* checking
> the IOSB. For code written like that, all bets are off now -- no need to
> wait for a new or different compiler.
The iosb is read because of the if statement. The later use in the
printf will know that iosb had already been read, and can be reused. In
fact, a clever compiler could optimize that to instead do a printf of a
fixed string, where a 0 is inserted instead of the %x. Because we
actually know that iosb is 0 when inside the if...
Johnny
More information about the Info-vax
mailing list