From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a37:a58b:: with SMTP id o133mr8245259qke.418.1623502273572; Sat, 12 Jun 2021 05:51:13 -0700 (PDT) X-Received: by 2002:a25:4641:: with SMTP id t62mr13206861yba.253.1623502273366; Sat, 12 Jun 2021 05:51:13 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 12 Jun 2021 05:51:13 -0700 (PDT) Injection-Info: google-groups.googlegroups.com; posting-host=174.71.119.33; posting-account=ix5KpAoAAAD9zo_4u1FxHVmn1uZn7U_d NNTP-Posting-Host: 174.71.119.33 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: non-preemptive tasking on GNAT 2020 Windows 10 multicore AMD From: Dan Winslow Injection-Date: Sat, 12 Jun 2021 12:51:13 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:62192 List-Id: I am trying to achieve true non-preemptive tasking using gnat 2020 CE on a = windows 10 environment. I have placed this in the gnat.adc file: pragma Task_Dispatching_Policy(Non_Preemptive_FIFO_Within_Priorities); Without this gnat.adc setting, the tasks switched back and forth a great de= al, as you would expect with preemptive tasking. Putting the pragma in the = gnat.adc file seemed to affect the granularity of the task switching on my = test program below, in that it lengthened the time that each task executed = consecutive loops, but they still switched over to each other eventually. H= ere is the test program: with Ada.Text_IO; Use Ada.Text_Io; =20 procedure Test is Task Type One is End; =20 Task Type Two; Task body One is x : Integer :=3D 0; Begin put_line("one"); Loop x:=3Dx+1; if x > 10000000 Then exit; end if; =20 End Loop; Put_line("Task one done, x=3D" & x'img); End; Task body Two is x : Integer :=3D 0; Begin put_line("two"); Loop x:=3Dx+1; if x > 1000 Then exit; end if; =20 End Loop; Put_line("Task two done, x=3D" & x'img); End; a : One; B : two; begin =20 Null; End; Here is the compile line: gnatmake -gnat2012 -gnatX -f -g test.adb -gnatwA -I. -I.. -D obj And here is the output: one two Task two done, x=3D 1001 Task one done, x=3D 10000001 I expected the opposite, that task one would execute first, which it did, b= ut that it would also finish first because there's no reason for it to yiel= d to two without preemption. It looks to me like I am not actually getting = non-preemptive tasking, and I would like to know why. After some looking I found the 2012 attribute 'with CPU', and produced test= code : With System.Multiprocessors; use System.Multiprocessors; with Ada.Text_IO; Use Ada.Text_Io; =20 procedure Test is Task Type One with Cpu=3D>1 is End; =20 Task Type Two with Cpu=3D> 1 is end; =20 x,y : integer :=3D 0; limit : integer :=3D 1000000; Task body One is Begin put_line("one"); Loop if y > 0 then=20 raise tasking_error; end if; =20 x:=3Dx+1; if x > limit Then exit; end if; =20 End Loop; Put_line("Task one done, x=3D" & x'img); Exception When others =3D> put_line("task one died, x=3D" & x'img); =20 End; Task body Two is Begin put_line("two"); Loop y:=3Dy+1; if y > limit Then exit; end if; =20 End Loop; Put_line("Task two done, y=3D" & y'img); Exception When others =3D> put_line("task two died"); =20 End; a : One; B : two; begin put_line(Number_Of_CPUs'img & " cpu's");=20 While (x < limit+1) or (y < limit+1) loop Delay 0.0; End Loop; =20 put_line("main done, x " & x'img & " y " & y'img); End; which produces output one two 24 cpu's task one died, x=3D 310528 Task two done, y=3D 1000001 ^C (of course, I have to ctl-c out since main never finishes.) This happens whether or not I have the scheduling pragma in gnat.adc. Does = Windows just not respect processor assignment and/or the scheduling pragma? (Sorry for no code blocks, not sure how to do that here)