comp.lang.ada
 help / color / mirror / Atom feed
From: Larry Coon <larry@assist.org>
Subject: Re: Array of tasks
Date: 1997/12/09
Date: 1997-12-09T00:00:00+00:00	[thread overview]
Message-ID: <348DD9B5.11CD@assist.org> (raw)
In-Reply-To: 348DC3C0.7555@gsfc.nasa.gov


Stephen Leake wrote:

> I was hoping an access discriminant would do the trick, but I ended up
> with dynamically allocating the semaphores. Maybe you can fiddle some
> more. I added the bodies so others can compile if they want.

[code snipped]

Stephen,

Thanks for the reply.  The discriminants were something I hadn't thought
of.  The only problem is that I'm already using default discriminants
for
something else, and I'm not sure how to make them work together.  Sorry
I
wasn't complete with my contrived example -- I was trying to reduce the
problem to essentials by eliminating code that wasn't part of the
problem,
and I failed to include code that turned out to be relevant to your
solution.

Okay, to be a little more complete -- My tasks are each assigned a task
number, and I use a discriminant with a default to do it.  Here's my
code again, this time with the default stuff implemented:

procedure main is
  protected type semaphore is
    entry seize;
    procedure release;
  private
    available:  boolean := true;
  end semaphore;

  protected body semaphore is separate;

  protected counter is
    function get_next return integer;
  private
    data:   integer := 1;
  end counter;

  protected body counter is
    function get_next return integer is
      return_val: integer;
    begin
      return_val	:= data;
      data		:= data + 1;
      return return_val;
    end get_next;
  end counter;

  task type t (task_no: integer := counter.get_next);
  task body t is separate;

  task_count: positive;
begin -- main
  put ("Enter number of tasks: ");
  get (task_count);
  declare
    subtype task_range is integer range 1..task_count;
    semaphore_array: array (task_range) of semaphore;
    task_array: array (task_range) of t;
  begin
    null;
  end;
end;

-- And here are the implementation for the "separate" things:
separate (main)
protected body semaphore is
   entry Seize when Available is
   begin
      Available := False;
   end Seize;

   procedure Release
   is begin
      Available := True;
   end Release;
end semaphore;

separate (main)
task body T is
begin
   Semaphore_Array (1).Seize;
end T;


Larry Coon
University of California
larry@assist.org
and lmcoon@home.com




  reply	other threads:[~1997-12-09  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-09  0:00 Array of tasks Larry Coon
1997-12-09  0:00 ` Stephen Leake
1997-12-09  0:00   ` Larry Coon [this message]
1997-12-10  0:00     ` Mats Weber
1997-12-10  0:00 ` Anonymous
1997-12-10  0:00 ` Jean-Pierre Rosen
replies disabled

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