[comp.sys.encore] C code not re-entrant!

robison@m.cs.uiuc.edu (04/07/89)

This is a partial flame from a very irate user, but may prevent other
people from getting irate.  (Excuse me if this horse has already been
flogged.)

	C FUNCTIONS THAT RETURN STRUCTS ARE NOT RE-ENTRANT!

At least for the Max C compiler (02.00.r088).  This fact is apparently well 
known by C compiler hackers, but not publicized.  One would think that vendors
of parallel machines would have C compiler's that generate re-entrant code.

For those using shared-memory parallel processing, the problem is this.  
Suppose we have:

	typdef struct {
		...
	} Foo;

	Foo bar( int i ) {
		...
	}

The function 'bar' is not reentrant.  The reason is that the return value is 
not returned on the stack, but in a global location.  At the assembly-code 
level, procedure 'bar' returns a pointer to a global location.  Normally the 
caller immediately copies this global location when 'bar' returns.
But with parallel calls to 'bar', two values will simultaneously
attempt to occupy the global location, with ensuing chaos.

This is particularly frustrating since pure functions are one of the
safest ways to do parallel programming, but cc compiles them into code
with hidden side effects.

Arch D. Robison
University of Illinois at Urbana-Champaign
	
CSNET: robison@UIUC.CSNET
UUCP: {pur-ee,convex}!uiucdcs!robison
ARPA: robison@CS.UIUC.EDU (robison@UIUC.ARPA)