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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Timeouts in Ada Date: Thu, 17 Jul 2014 11:48:56 +0200 Organization: cbb software GmbH Message-ID: <1uas8lp70tji4.1jnnhryhd49tu$.dlg@40tude.net> References: <50bdb713-7ce1-411b-810b-9bdee1d26b7a@googlegroups.com> <19saet0lg87pr.yqkkaxl011gq.dlg@40tude.net> <8a8353c8-3a8e-4b42-9c94-6d6d095faf1d@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ot/DC7n2aCvt5pcTM4dZCw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:20994 Date: 2014-07-17T11:48:56+02:00 List-Id: On Thu, 17 Jul 2014 01:59:53 -0700 (PDT), NiGHTS wrote: > On Thursday, July 17, 2014 3:42:21 AM UTC-4, Dmitry A. Kazakov wrote: >> >> This is a timed entry call. The callee must be a task's or a protected >> object's entry. > > Are you suggesting that the select/or would not work inside the main > procedure? ? > Say I had a subroutine which submits a query to a database in a > non-blocking way. Thus it is a loop which waits for a response from the > database. The example is quite unrealistic. If the DB client supported asynchronous requests, then it would be very unlikely polling. Any reasonably designed client would use some waitable OS object instead, i.e. waiting will be non-busy. > Say the caller of this subroutine wants to have a timeout > condition attached to this request. In the polling scenario, the polling loop must check for timeout being expired. For non-busy waiting, OS usually provides means to specify a timeout. E.g. WaitForSingleObject under Windows. > To me the obvious C-style solution here is to pass the timeout value to > the procedure and have it check its elapsed time as part of the loop, then > break if it takes too long with an exception or a return value stating > that a timeout occurred. This is how most non-Ada API do. An Ada API would have a choice between dressing the call up as a plain subroutine and thus passing the timeout as a parameter or else exposing the task or protected object and thus allowing explicit timed entry calls on the caller's side. > My question is this: Is there a more elegant way to do this timeout > checking in Ada, perhaps using this select/or system? An elegant way is the latter, i.e. exposing an entry. > Or is the C-style > technique as elegant as it gets for this kind of problem? This is inelegant but has certain advantages: 1. Protected objects and tasks in Ada do not really support OO and programming by extension. 2. Usually when the timeout is expired you want some action of the callee's side, e.g. changing the state of the I/O request on the server like canceling the outstanding requests, performing a rollback etc. A timed entry call offers only caller's side response. It is possible to incorporate server's side actions with entry calls using the technique of requeueing, as I described earlier, but it could make things a bit overcomplicated. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de