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 I. Eachus" Subject: Re: Ada Protected Object Tutorial #1 Date: 1999/12/21 Message-ID: <3860075D.FFB0130A@mitre.org>#1/1 X-Deja-AN: 563578365 Content-Transfer-Encoding: 7bit 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> <86u2lgvumy.fsf@ppp-116-44.villette.club-internet.fr> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.mitre.org X-Trace: top.mitre.org 945817020 20433 129.83.41.77 (21 Dec 1999 22:57:00 GMT) Organization: The MITRE Corporation Mime-Version: 1.0 NNTP-Posting-Date: 21 Dec 1999 22:57:00 GMT Newsgroups: comp.programming.threads,comp.lang.ada Date: 1999-12-21T22:57:00+00:00 List-Id: Kaz Kylheku wrote: > What do you do if you need a protected procedure to call out into > some other module which then calls back? > > Using explicit locks, I just unlock, do the call, lock again > thereby avoiding deadlock. Although I think that the other issues have been explained throughly, there are a couple of special things about using protected objects in this situation. First note that we are discussing protected OBJECTs. A protected object can and will have state variables which are protected by the object. But, since a protected object can and will run in multiple threads, per thread locking is no help. However, if you want to do allow potentially recursive calls on a per thread basis, it is not that hard to do, and surprisingly the overhead is trivial. Have the calling task pass in its identity--Ada.Task_ID.Current_Task--and save it when locking. Of course the easy implementation is to use a value of Null_Task_ID to mean unlocked. But there is a much more interesting case. Assume you have an array of state variable sets, including Task_IDs. For example, you are interfacing to a (local) database on behalf of many client tasks. Each task can have a transaction in process, with the protected object serializing interaction with the data, while the calling tasks can interleave other (potentially blocking) actions into the transaction. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...