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 18:24:22 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!EU.net!sun4nl!fwi.uva.nl!not-for-mail From: casper@fwi.uva.nl (Casper H.S. Dik) Newsgroups: comp.lang.ada Subject: Re: Easily-Read C++? Date: 11 Oct 1994 14:44:18 +0100 Organization: FWI, University of Amsterdam Distribution: world Message-ID: <37e4ri$7es@mail.fwi.uva.nl> References: <1994Oct7.153254.29848@swlvx2.msd.ray.com> <374uke$8mo@delphi.cs.ucla.edu> <37bno4$ko4@gnat.cs.nyu.edu> <1994Oct11.090047.9190@sei.cmu.edu> NNTP-Posting-Host: mail.fwi.uva.nl Date: 1994-10-11T14:44:18+01:00 List-Id: firth@sei.cmu.edu (Robert Firth) writes: >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. Why? The only think you need to take care of in C when writing multi-threaded code is using proper (explicit) locking of global data. Most of the foo++ usages in C are of automatic variables. Those aren't shared between threads or even function invocations and consequently there is no problem with c++ kind of code. However, when incrementing a global variable one should do something like this: set_write_lock(foo_lock); foo++; unlock_write_lock(foo_lock); The problem with C multi-threading is making the locking explicit. You may also need to make such variable "volatile" which is C-speak for "can be modified behind my back". Locking is also necessary for reading variables that are shared between threads (and modified by some of those threads). I really don't see what the difference between "foo = foo + 1" or foo++ is in this context. Casper