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,FREEMAIL_FROM autolearn=ham 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 13:29:37 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.freenet.de!not-for-mail From: Jan Prazak Subject: Re: gnat: time-slicing Date: Mon, 15 Jul 2002 22:30:53 -0100 Newsgroups: comp.lang.ada Message-ID: References: User-Agent: Pan/0.11.2 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso885915 Content-Transfer-Encoding: 8bit X-Comment-To: "David C. Hoos" NNTP-Posting-Host: 213.7.199.44 X-Trace: 1026764975 news.freenet.de 26988 213.7.199.44 X-Complaints-To: abuse@freenet.de Xref: archiver1.google.com comp.lang.ada:27119 Date: 2002-07-15T22:30:53-01:00 List-Id: On Mon, 15 Jul 2002 16:16:17 -0100, David C. Hoos wrote: > 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 the result was a b a b with Delay 0.01 after *every* Put_Line and a a b b with no delays. The tutorial mentions, that ab ab can be produced even on systems with only one CPU, depending on the compiler. > 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. Task_A begins after the main program in my case. > There is no way your program can be deterministic over different OSs, > and hardware platforms. Time slicing will not do it either. Yes, let us close this topic. I have what I want, because the test program with task "Beep" works as expected (I want to make a similar program). >> Think of a timer: >> >> task Timer is ... >> ... >> loop >> Delay 1.0; >> Put(current_time); >> end loop; >> ... > This restatement of what you want to do is completely different from > what you described in your original post. I don't think so. It's different, but not at all. Let me discuss my "Beep" program.In my first posting, there is Put_Line, which lets execute another statements (tasks) only when it has finished writing the text ('a'), and so I expected "Get(C)" also to stop all running processes, until the user gives a character and presses enter. But actually it permits other tasks to run at the same time, which I haven't expected. > If I understand what you want is a task that will run once per some time > interval > independently of the other task(s). yes, for instance > 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; This looks like an example from the Ada95 reference manual. > 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. As I could see, "Delay 0.0" is ignored by the compiler (running program). It has no effects on other tasks. I have tried to add "Delay 0.0" after each "Put_Line" into the first example program, and the result was a a b b (same as with no delays). Maybe there is something like "if Duration = 0.0 then skip_statement" in the definition of Delay. --- Thanks, Jan