From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ff5003422436e4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-11 17:44:08 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!fs7.ece.cmu.edu!cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!news.sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Subject: Re: Easily-Read C++? Message-ID: <1994Oct11.090047.9190@sei.cmu.edu> Sender: netnews@sei.cmu.edu (Netnews) Organization: Software Engineering Institute References: <1994Oct7.153254.29848@swlvx2.msd.ray.com> <374uke$8mo@delphi.cs.ucla.edu> <37bno4$ko4@gnat.cs.nyu.edu> Date: Tue, 11 Oct 1994 09:00:47 EDT Date: 1994-10-11T09:00:47-04:00 List-Id: In article <37bno4$ko4@gnat.cs.nyu.edu> dewar@cs.nyu.edu (Robert Dewar) writes: >An interesting point about the ++ notation is that it appears as far as >I can tell to give undefined results or rather implementation dependent >resultsin the presence of threads, in particular, is it possible for >++c to store a 4 in memory (where there was a 3 before), and then return >6 as a result of rereading c, where intermediate updates have occurred. Unfortunately, as far as I can see this is almost inevitable. The construct expands, semantically, to valof { c := c+1; resultis c } Well, one can try to make the increment an atomic operation, giving, for instance (PE3200 code) LIS R1, 1 ; load 1 into a temp register AM R1, C(RD) ; add it to memory cell C but then you are forced to do another read L R0, C(RD) ; now load new value of C into result reg and, as Robert Dewar mentioned, who knows what has happened in the meantime? The alternative is to make the result computation essentially atomic: L R0, C(RD) ; get value of C into result reg AIS R0, 1 ; add 1 to it and leave as result ST R0, C(RD) ; and store back new value and, again, anything could have happened to the variable C between the read and the write. So the compiler writer, with the best will in the world (a rare quality, I fear) is still pretty much stuck. The C code I've seen is absolutely littered with this stuff. I am continually amazed that *anything* still works when people write true multitasking code in C.