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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: RFC: Prototype for a user threading library in Ada Date: Sat, 25 Jun 2016 22:21:16 -0500 Organization: JSA Research & Innovation Message-ID: References: <58b78af5-28d8-4029-8804-598b2b63013c@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1466911274 12477 24.196.82.226 (26 Jun 2016 03:21:14 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sun, 26 Jun 2016 03:21:14 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:30939 Date: 2016-06-25T22:21:16-05:00 List-Id: "Dmitry A. Kazakov" wrote in message news:nkl8bm$19q7$1@gioia.aioe.org... > On 2016-06-24 02:38, rieachus@comcast.net wrote: >> I don't get it. If this is your "motivation": >> >>> The motivation is a two-liner. Let you have some consumer of data: >>> >>> procedure Write (Buffer : String; Last : out Integer); >>> >>> It may take less than the whole string when called, but will take more >>> data later. So, the parameter Last. Now you want to write a program in a >>> *normal* way: >>> >>> Write ("This"); >>> Write ("That"); >>> >>> That's it. >> >> You may want to make your Last parameter in or in out, but that's a >> detail. > > It is not a detail. The caller of Write does not know how much data the > transport layer is ready to accept. That is the nature of non-blocking > I/O. Write takes as much data it can and tells through Last where the > caller must continue *later*. > > A blocking busy-waiting wrapper looks this way: > > procedure Write (Buffer : String) is > First : Integer := Buffer'First; > Last : Integer; > begin > loop > Write (Buffer (First..Buffer'Last), Last); > exit when Last = Buffer'Last; > First := Last + 1; > end loop; > end Write; You forgot the "delay 0.0;" (or "yield;" as Ada 2012 aliased it): procedure Write (Buffer : String) is First : Integer := Buffer'First; Last : Integer; begin loop Write (Buffer (First..Buffer'Last), Last); exit when Last = Buffer'Last; First := Last + 1; delay 0.0; end loop; end Write; The delay gives up the processor so that other tasks can run. It's how most I/O works in Janus/Ada. (Note that if you know something about the latencies of Write, you can use a better value than "0.0", so you don't try again until you're pretty sure the system is ready. For instance, for socket I/O we typically use 0.01, so the program isn't churning and doing nothing. [Although we usually use a system of increasing delays, so that if it is ready almost immediately, we're continuing to write, else we're waiting longer and not wasting time trying something that's unlikely to be ready.]) That, combined with proper tasking runtimes, would seem to provide better results than doing all one thing (task = thread) or all othe ther (some fancy coroutine system). Randy.