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-13 09:15:14 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!vixen.cso.uiuc.edu!newsrelay.iastate.edu!newsxfer.itd.umich.edu!europa.eng.gtefsd.com!uhog.mit.edu!news.kei.com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!milod From: milod@netcom.com (John DiCamillo) Subject: Re: Easily-Read C++? Message-ID: Organization: NETCOM On-line Communication Services (408 261-4700 guest) 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> <37e4ri$7es@mail.fwi.uva.nl> Date: Wed, 12 Oct 1994 16:38:07 GMT Date: 1994-10-12T16:38:07+00:00 List-Id: casper@fwi.uva.nl (Casper H.S. Dik) writes: >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. >I really don't see what the difference between "foo = foo + 1" >or foo++ is in this context. Actually, in C++ there may be a big difference in readability. Since operator ++ is a function, it can be overridden to include the locking: void f( Protected& foo ) { foo++; } The class template Protected wraps the mutation operators in lock()/unlock() pairs to guarantee proper operation in the presence of threads. (Other mutation functions on Foo can not be Pro- tected quite so simply.) -- c'iao, milo ================================================================ John DiCamillo Pinin' for the fjords? milod@netcom.com What kind of talk is that?