comp.lang.ada
 help / color / mirror / Atom feed
From: rlk@VisiCom.COM
Subject: Re: Tasks in ADA
Date: Fri, 24 Apr 1992 13:15:28 PDT	[thread overview]
Message-ID: <9204242015.AA10087@amstel.VisiCom.COM> (raw)

> Date: 18 Apr 92 01:31:21 GMT
> From: rhlab!bkuhn@uunet.uu.net  (bmk Bradley Kuhn)
> Subject: Tasks in ADA
> Message-ID: <463@rhlab.UUCP>
> 
>    Is there a way to find out how a particular implimentation of ADA deals
> w/ tasks (i.e. time slicing or genuine multi-tasking).


Of course, RTFM if you can.  But another way of determining it is
like so:

(this should be target-independent, but was compiled with TeleSoft's
RISCAda v1a host system, which does support time slicing)

-----------------------------------
with Text_IO;
with System;

procedure Slice_Test is

  pragma Priority(System.Priority'Last);

  task type Slicer is
    pragma Priority(System.Priority'First);
    entry start;
  end Slicer;

  Num_Tasks : constant := 10;
  type ID is range 1..Num_Tasks;

  type Count is range 0..System.Max_Int;

  Counts : array(ID) of Count := ( others => 0 );
  Slicers : array(ID) of Slicer;

  ID_finger : ID := 0;
  pragma Shared(ID_Finger);

  function Get_ID return ID is
  begin
    ID_Finger := ID_Finger + 1;
    return ID_Finger;
  end Get_ID;

  task body Slicer is
    Me : ID := Get_ID;
  begin
    accept start;
    text_io.put_line("Task " & ID'image(Me) & " up & running");
    loop
      Counts(Me) := Counts(Me) + 1;
    end loop;
  exception
    when others => 
      Text_IO.Put_Line("Exception in slicer " & ID'Image(Me));
  end Slicer;


begin
  for I in ID loop
    Slicers(I).Start;
  end loop;

  text_io.put_line("Main waiting 10 seconds");
  delay 10.0;

  text_io.put_line("Main killing off children");
  for I in ID loop
    abort Slicers(I);
  end loop;
  for I in ID loop
    text_io.put_line("Task " & ID'image(I) & 
		      " count is " & Count'image(Counts(I)));
  end loop;
end Slice_Test;
-----------------------------------


This test creates an array of 10 low-priority tasks, each of which
waits to be started by the main task.  Once started, they each 
enter an endless loop, incrementing a counter.

The main task wakes up after 10 seconds, and reports on the progress
each of the tasks has in incrementing their counter.

If time slicing is not supported, you'll see task 1 hogging all of the 
CPU:

      Main waiting 10 seconds
      Task  1 up & running
      Main killing off children
      Task  1 count is  12460460
      Task  2 count is  0
      Task  3 count is  0
      Task  4 count is  0
      Task  5 count is  0
      Task  6 count is  0
      Task  7 count is  0
      Task  8 count is  0
      Task  9 count is  0
      Task  10 count is  0


If time slicing is supported (and enabled!) then you'll get a more even
sharing of the CPU among the children.

      Main waiting 10 seconds
      Task  1 up & running
      Task  2 up & running
      Task  3 up & running
      Task  4 up & running
      Task  5 up & running
      Task  6 up & running
      Task  7 up & running
      Task  8 up & running
      Task  9 up & running
      Task  10 up & running
      Main killing off children
      Task  1 count is  1195902
      Task  2 count is  1193589
      Task  3 count is  1176106
      Task  4 count is  1200294
      Task  5 count is  1185150
      Task  6 count is  1210111
      Task  7 count is  1207654
      Task  8 count is  1189524
      Task  9 count is  1181912
      Task  10 count is  1230723


Please note that, depending on your runtime, this test may not terminate
after reporting the tenth task's count.  This depends on whether or not
your runtime supports asynchronous aborts.

	.Bob.


p.s. it's "Ada" (not an acronym)

             reply	other threads:[~1992-04-24 20:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-04-24 20:15 rlk [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-04-30 17:24 Tasks in Ada rlk
1992-04-26 19:14 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!l
1992-04-22  3:57 Tasks in ADA news.u.washington.edu!milton.u.washington.edu!mfeldman
1992-04-18  1:31 bmk Bradley Kuhn
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox