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: 103376,5d05ccde5cefb836 X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: Blocking protected ops (was: Tasks and C/C++ code) Date: 1998/11/27 Message-ID: <365EEAFA.2D636FD2@elca-matrix.ch>#1/1 X-Deja-AN: 416262652 Content-Transfer-Encoding: 7bit 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-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: ELCA Matrix SA Mime-Version: 1.0 Reply-To: Mats.Weber@elca-matrix.ch Newsgroups: comp.lang.ada Date: 1998-11-27T00:00:00+00:00 List-Id: David Botton wrote: > > After all the discussion on this issue, I am not sure how to implement a > call to gethosbyname any more. > > Would some one post a correct implementation of this and if one can wrap > gethostbyname in to a protected type so it can be called by multiple task > instances even if it (gethostbyname) is not thread safe. An example of how to do it can be found in: or copy this code (compiled, not tested): protected Semaphore is entry Seize; entry Release; private Busy : Boolean := False; end Semaphore; protected body Semaphore is entry Seize when not Busy is begin Busy := True; end; entry Release when Busy is begin Busy := False; end; end Semaphore; function Gethostbyname (Name : in System.Address) return System.Address; -- pointer to hostent pragma Import(C, Gethostbyname); function Protected_Gethostbyname (Name : in System.Address) return System.Address is Result : System.Address; begin Semaphore.Seize; Result := Gethostbyname(Name); Semaphore.Release; return Result; exception when others => Semaphore.Release; raise; end Protected_Gethostbyname; it would be nice to put the call to gethostbyname inside a protected procedure (so that you need only one protected call instead of two), but this does not seem to be allowed as gethostbyname could be potentially blocking.