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,474d28ddf953b3c1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-05 14:10:30 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Subject: Re: Reference Counting (was Re: Searching Method for Incremental Garbage Collection) Message-ID: <1994Dec5.155913.14005@sei.cmu.edu> Sender: netnews@sei.cmu.edu (Netnews) Organization: Software Engineering Institute References: Date: Mon, 5 Dec 1994 15:59:13 EST Date: 1994-12-05T15:59:13-05:00 List-Id: In article hbaker@netcom.com (Henry G. Baker) writes: >You should be prepared for huge overheads when updating reference >counts on shared objects in a multiple-threaded (multiple-tasked) >program. Not necessarily. The PE3200, for example, has an "add to memory" insturction that seems tailor made for this problem. AM reg, mem In practice, the constants +1 and -1 were so often used as the addend that I simply had the compiler permanently allocate two registers to them, so any reference counting became a single atomic instruction. Well, things are now riscier. So here's another way: make the reference counting a sequence of instructions: L reg, mem AI reg, 1 S reg, mem In the task context switch, check whether you interrupted that sequence *and the memory address points into the shared heap* (trivial on a risc machine with essentially one memory address mode), and simply slave whatever didn't get done. On some machines, it may be cheaper always to slave rather than even bother checking the address.