C and real hardware - (nf)

utzoo!decvax!decwrl!sun!megatest!ubvax!arvind utzoo!decvax!decwrl!sun!megatest!ubvax!arvind
Fri Apr 29 19:26:03 AEST 1983


#R:rlgvax:-34500:ubvax:4100001:000:981
ubvax!arvind    Apr 29 19:10:00 1983

***** ubvax:net.lang.c / rlgvax!tom /  4:40 pm  Apr 28, 1983
RE: possible undesired optimization of code like:

	while (ADDR->c_reg&BUSY)
		;

I have worked with drivers a great deal in older versions of UNIX and
never had a problem with optimization eliminating the repeated memory
reference.  One reason may be that since UNIX is a timesharing system,
there are very few actual "busy waits" as above (a neat way to hang
a system) but instead:

	while (ADDR->c_reg&BUSY)
		sleep((caddr_t)&x, PRIBIO);

The subroutine call in the loop is enough to turn off any optimization.

But otherwise, in the first example it would seem reasonable to optimize
out the memory reference, to the programmer's displeasure.  This could
become a more widespread problem when shared data spaces cause user
programs to use the same type of code. The "unregister" or "volatile"
declaration mentioned could prove useful (I prefer the second term).

Tom Beres
{we13, mcnc, seismo}!rlgvax!tom
----------




More information about the Comp.lang.c mailing list