Path: utzoo!attcan!uunet!husc6!bloom-beacon!mit-eddie!bbn!rochester!stuart From: stuart@cs.rochester.edu (Stuart Friedberg) Newsgroups: comp.lang.c Subject: Re: volatile, shared memory, and synchronisation Message-ID: <9928@sol.ARPA> Date: 23 May 88 23:36:44 GMT References: <20345@pyramid.pyramid.com> <833@mcdsun.UUCP> <9916@tekecs.TEK.COM> <199@gannet.cl.cam.ac.uk> <11629@mimsy.UUCP> Reply-To: stuart@cs.rochester.edu (Stuart Friedberg) Organization: U of Rochester, CS Dept., Rochester, NY Lines: 32 In article <199@gannet.cl.cam.ac.uk> scc@cl.cam.ac.uk (Stephen Crawley) writes: >... multi-process applications that use shared memory. Consider two >processes A and B with a shared variable v, and the following code > int x = v /* A1 */ | v = 2 /* B1 */ > int y = v /* A2 */ | In article <11629@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >Even *with* volatile declarations, you get no solid guarantee. Suppose >that v is a `volatile int', and that you are running on a bit-oriented >binary machine and v has been placed across two different memory >banks. [...] >This is perhaps unlikely, but in fact something similar could >easily happen on a multi-cpu R2000-based system (assuming 32 bit >integers), although not with the values 1 and 2. The BBN Butterfly (but not the Butterfly+ nor the Butterfly 2, I believe) has exactly this problem. Each processor node is based on the MC68000, with lots of fancy coprocessor support to allow each 68K to issue memory references transparently to both local and remote physical memory. Any memory location can be accessed by as many as 256 processors. *Really* volatile. :-) However, only the initial coprocessors (PNC's) only supported 16-bit (word) operations atomically. 32-bit operations could, and very *often* did, have unwanted interleavings. To do the 32-bit ops, you have to lock the memory you want first in your software. Needless to say, this is less efficient than letting the hardware do it for you. It was doubly obnoxious, since we have people here investigating highly concurrent data structures that don't need locking *provided* some basic operations like add or compare-and-swap could be done atomically. Stu Friedberg {ames,cmcl2,rutgers}!rochester!stuart stuart@cs.rochester.edu