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,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,63360011f8addace X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-15 10:17:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!isdnet!enst!enst.fr!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: gnat: time-slicing Date: Mon, 15 Jul 2002 12:16:17 -0500 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1026753423 68124 137.194.161.2 (15 Jul 2002 17:17:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Mon, 15 Jul 2002 17:17:03 +0000 (UTC) Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Original-Cc: janp9@gmx.net Xref: archiver1.google.com comp.lang.ada:27116 Date: 2002-07-15T12:16:17-05:00 ----- Original Message ----- From: "Jan Prazak" Newsgroups: comp.lang.ada To: Sent: Monday, July 15, 2002 2:10 PM Subject: Re: gnat: time-slicing > Where should this be placed? This looks like the suggestions from David, > he suggested "Delay 0.02" after each Put_Line, but it gives not the > result I want. What result did it give? When I ran your program on my RedHat 6.2 box with dual 1.0 gHz. processors, it gave the result you wanted. When I ran it on my Win2K box with one 1.8 gHz. processor, it gave the reult a a b b When I added the suggested delay statements, it gave the result b a b a which interleaves the actions of the tasks, but with Task_A beginning execution before the main program. There is no way your program can be deterministic over different OSs, and hardware platforms. Time slicing will not do it either. > > Think of a timer: > > task Timer is ... > ... > loop > Delay 1.0; > Put(current_time); > end loop; > ... > > The task uses one Put, which puts current time somewhere on the screen. > And this task has to be completely independent from other tasks (= main > procedure). There has to be a way to do this with gnat, and that's also > my question. I don't want to slow down other tasks with "Delay", just to > let Timer-task do the next step (for example when doing some difficult > computing, maybe array-sorting or similar things), so there has to be a > "direct" way (like a pragma). This restatement of what you want to do is completely different from what you described in your original post. If I understand what you want is a task that will run once per some time interval independently of the other task(s). Here is an example of how that can be done: Interval : constant Duration := 1.0; use type Ada.Calendar.Time; Next_Time : Ada.Calendar.Time := Ada.Calendar.Clock + Interval; begin loop Delay until Next_Time; Next_Time := Next_Time + Interval; ...... end loop; Since delays are for a _minimum_ of the specified time, using a simple delay statement in a "timer" will result in an accumulation of time error. What I have shown above will put the task on the ready queue for its priority at precisely Interval-second intervals without accumulation of time errors. However, just how soon after the task becomes ready it will actually run depends on what other tasks are running, their priorities relative to the priority of the "timer" task, and whether these other tasks are "civilized" about yielding the CPU from time-to-time if they are compute- intensive. For example, if you have a compute-intensive task that executes a delay 0.0 statement no time will be lost if there is no other task ready to run. But, when your timer task is ready, and is of a higher priority, it will run when given the opportunity.