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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ffc1e,fb45e48e8dddeabd X-Google-Attributes: gidffc1e,public X-Google-Thread: 103376,fb45e48e8dddeabd X-Google-Attributes: gid103376,public From: kaz@ashi.footprints.net (Kaz Kylheku) Subject: Re: Ada Protected Object Tutorial #1 Date: 1999/12/18 Message-ID: #1/1 X-Deja-AN: 562419784 Cache-Post-Path: ashi.FootPrints.net!unknown@localhost References: <839toq$pu$1@bgtnsc03.worldnet.att.net> <385AC716.7E65BD5C@averstar.com> X-Complaints-To: abuse@direct.ca X-Trace: brie.direct.ca 945548380 204.239.179.1 (Sat, 18 Dec 1999 12:19:40 PST) Organization: Psycho-Neurotic Institute for The Very, Very Nervous X-Cache: nntpcache 2.3.3b3 (see http://www.nntpcache.org/) User-Agent: slrn/0.9.5.7 (UNIX) Reply-To: kaz@ashi.footprints.net NNTP-Posting-Date: Sat, 18 Dec 1999 12:19:40 PST Newsgroups: comp.programming.threads,comp.lang.ada Date: 1999-12-18T00:00:00+00:00 List-Id: On Fri, 17 Dec 1999 23:28:22 GMT, Tucker Taft wrote: >Trying to provide this same capability via an "API" >is quite awkward, as it requires the programmer to bundle up an operation and >"submit" it along with some kind of boolean function, and allow the >underlying run-time system decide who evaluates the boolean function >and who executes the operation. Almost all APIs instead are set up >so that the programmer's code evaluates the boolean condition outside >of the run-time system, and must do so repeatedly each time control >returns to the user's code, to ensure that the boolean is true by >at the moment when the user's code gets control. This can result This is practical. The condition variable wait might be done inside a protected kernel. It would be impractical to have, say, a UNIX kernel call back into application code to determine if some predicate is true. >in even more unnecessary context switches, and/or bugs if the >programmer neglects to build the evaluation of the boolean condition >into a loop around the condition-variable "wait" operation. That loop around a condition variable wait is needed to resolve spurious wakeups and race conditions. The logic gives more ways to the implementor to provide a correct implementation. Suppose your thread is waiting on a condition, and the condition is signalled. It's time to reacquire the monitor (or mutex). But a thread running on another CPU grabs it first and changes the object so that the condition the original thread waited for is no longer valid. I believe that providing guarantees against this sort of occurence introduces overhead; that is, the cure may be worse than the ailment, particularly on multiprocessors. >As one data point, a classic producer/consumer example with a >bounded buffer, when coded using a protected type versus using >mutex/condition variables, results in typically half as many >locks and unlocks, and one third as many context switches between >the producer and the consumer. The mutex/condition variable >approach involves so much more work because each thread ends up >doing all the work "itself," rather than allowing the other thread >to do a little bit of work on its behalf while it already holds the lock. Is there a paper about this which argues the case in more detail?