Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!iuvax!pur-ee!uiucdcs!uiucdcsb!robison From: robison@uiucdcsb.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: hack to fake volatile Message-ID: <165600036@uiucdcsb> Date: 3 Apr 88 21:23:00 GMT References: <4700010@uiucdcsm> Lines: 25 Nf-ID: #R:uiucdcsm:4700010:uiucdcsb:165600036:000:870 Nf-From: uiucdcsb.cs.uiuc.edu!robison Apr 3 15:23:00 1988 Scott Daniels (daniels@teklds.UUCP) pointed out a bug in my original hack to fake "volatile". There are situations involving writes-only which an "optimizer" may incorrectly transform. One needs a call to "Munge" in both the read and write routines to "flush the caches", so to speak. int _X; /* local to WriteX and ReadX */ #define WriteX(a) (_X=a, Munge(&_X)) /* Munge is a secret no-op */ #define ReadX (Munge(&_X), _X) I'm not sure how to formally verify this hack. I suppose one could argue that any asynchronous writes and reads could be simulated by the Munge calls, and therefore the optimizer must keep its paws off. But this is far from a convincing argument. Arch D. Robison University of Illinois at Urbana-Champaign CSNET: robison@UIUC.CSNET UUCP: {ihnp4,pur-ee,convex}!uiucdcs!robison ARPA: robison@B.CS.UIUC.EDU (robison@UIUC.ARPA)