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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: Robert A Duff Subject: Re: Ada Protected Object Tutorial #1 Date: 1999/12/18 Message-ID: #1/1 X-Deja-AN: 562424455 Sender: bobduff@world.std.com (Robert A Duff) References: <839toq$pu$1@bgtnsc03.worldnet.att.net> <3858E5B3.9AB004E9@bton.ac.uk> <385984BC.1FB1@hello.nl> <86aen9z7qi.fsf@ppp-111-13.villette.club-internet.fr> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.programming.threads,comp.lang.ada Date: 1999-12-18T00:00:00+00:00 List-Id: kaz@ashi.footprints.net (Kaz Kylheku) writes: > This requires the procedures to be passed information about whether the > object is locked by this thread or not. For example, a hidden parameterr. No, the Ada rules require a compile-time determination of whether a given call is an "internal" call (no locking; assumed already locked), or an "external" call. There is no run-time overhead. > These solution requires some measure of clairvoyance: what if the protected > procedure calls into another subsystem which then calls back into a protected > procedure on the same object? How do you pass the ``already_locked'' knowledge > across calls to foreign subsystems? That situation is, by definition, an "external" call. It will attempt to lock the protected object, and since it's the same object, it will deadlock. It's only in well-defined (compile-time-known) cases that are defined as "internal" calls. By the way, I'm not sure exactly what you mean by "clairvoyance" in this case. > The solution is probably to use recursive locks, which check the ID of the > calling against an ownership ID stored in the lock. Recursive locks are > slightly inefficient because they have to retrieve the ID of the current thread > and compare it. If you want recursive locks in Ada, you have to program them yourself -- the run-time system doesn't do that automatically. - Bob