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: 103376,5d05ccde5cefb836 X-Google-Attributes: gid103376,public From: tmoran@bix.com (Tom Moran) Subject: Re: Blocking protected ops (was: Tasks and C/C++ code) Date: 1998/11/27 Message-ID: <365f243d.10100378@news.pacbell.net>#1/1 X-Deja-AN: 416327359 References: <364702E5.F6987321@hiwaay.net> <729ndu$jfo$1@nnrp1.dejanews.com> <72b35b$pll$1@nnrp1.dejanews.com> <87btm52jwl.fsf@zaphod.enst.fr> <3654746F.3C297E56@elca-matrix.ch> <87k90qunxl.fsf@zaphod.enst.fr> <36599BE3.BA30555B@elca-matrix.ch> <3659b3a8.386623@news.pacbell.net> <365AD980.5729FCD8@elca-matrix.ch> <365BE117.59209A5@elca-matrix.ch> <73mo00$24ik$1@news.gate.net> X-Complaints-To: abuse@pacbell.net X-Trace: typhoon-sf.snfc21.pbi.net 912205005 206.170.2.118 (Fri, 27 Nov 1998 14:16:45 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Fri, 27 Nov 1998 14:16:45 PDT Newsgroups: comp.lang.ada Date: 1998-11-27T00:00:00+00:00 List-Id: The Claw Windows binding uses WSAAsyncGetHostByName, which gets around most of the blocking. But more generally, to call a blocking routine in a task safe way, Mats Weber's example is basically what you need to do. If you are going to have multiple semaphores, you will want to create a protected semaphore type, so you can declare different semaphores for different resources. If your code between Seize and Release is complex, you might find it less error-prone to create a controlled type whose Initialize calls Seize and whose Finalize calls Release, to make sure those are both called properly, ie something like this: protected type Semaphore -- like Mats Weber's example, but a type type Access_Semaphore is access all Semaphore; type Seizer(What : Access_Semaphore) is new Ada.Finalization.Limited_Controlled with null record; procedure Initialize(S : in out Siezer); procedure Finalize(S : in out Siezer); ... procedure Initialize(S : in out Siezer) is begin Seizer.What.Seize; end Initialize; procedure Finalize(S : in out Siezer) is begin Seizer.What.Release; end Finalize; ... Gethostbyname_Protector : Semaphore; function Protected_Gethostbyname (Name : ... Owner : Seizer(Gethostbyname_Protector'access); begin return Gethostbyname(Name); end Protected_Gethostbyname; Another_Resource : Semaphore; procedure Something ... Owner : Seizer(Another_Resource'access); begin .... end Something; etc. (I've indicated elsewhere some of the reasons I think using System.Address is a poor idea, but that's an orthogonal issue.)