comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Elaboration checks
Date: 2000/02/14
Date: 2000-02-14T00:00:00+00:00	[thread overview]
Message-ID: <LfTp4.4128$Zp1.126881@newsread1.prod.itd.earthlink.net> (raw)
In-Reply-To: 38A6BB10.560D973A@dowie-cs.demon.co.uk

In article <38A6BB10.560D973A@dowie-cs.demon.co.uk> , Martin Dowie 
<martin@dowie-cs.demon.co.uk>  wrote:

> we plan to ensure that each of our packages provides an 'Initialise'
> routine to assign package-local initial values. all our tasks currently
> block on an 'accept Initialise' already.
>
> anything else we can do?

Here's an idea.  Each tack entry consumes run-time resources.  An
Initialize task entry is called only once, yet continues to consume
resources for the duration of the program.

If you're using Ada95, you can get rid of the Initialize entry by using
a Suspension_Object.  This may or may not reduce storage costs (it
depends on how SOs are implemented).

So instead of

package body P is

  task TO is
    entry Init;
    entry E;
  end TO;

  procedure Init is
  begin
    TO.Init;
  end;
...

  task body TO is
  begin
    accept Initialize;
    ...
  end TO;

end P;

You can replace the task entry with a suspension object:

with Ada.Synchronous_Task_Control;  use Ada.STC;
package body P is

  task TO is
    entry E;  -- note no Init entry
  end TO;

  Initialization : Suspension_Object;

  procedure Init is
  begin
    Set_True (Initialization);
  end Init;
...
  task body TO is
  begin
    Suspend_Until_True (Initialization);
  end TO;

end P;


You can also use a protected object, that is shared by all the tasks in
the system:

package Task_Initialization is

  protected Signal is

    entry Wait;

    procedure Send;

  private

    Initialized : Boolean := False;

  end Signal;

end Task_Initialization;


Now instead of every task having its own initialize entry, it simply
waits on the global task initialization signal object:

with Task_Initialization;
package body P is
...
  task body TO is
  begin
    Task_Initialization.Signal.Wait;
    ...
  end TO;

end P;

Now during startup, you only have to call one task initialization signal
object, instead of every task separately.  It's basically a way of
implementing a broadcast in Ada95.

These days, explicit Initialize entries for tasks are rarely necessary.
You can eliminate (all!) task entries by using protected objects, and
you can eliminate protected object entry queues by using suspension
objects.


--
The purpose of the system is what it does.

Stafford Beer





  parent reply	other threads:[~2000-02-14  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-13  0:00 Elaboration checks Martin Dowie
2000-02-13  0:00 ` Robert Dewar
2000-02-13  0:00   ` Martin Dowie
2000-02-14  0:00     ` Samuel T. Harris
2000-02-13  0:00 ` Jeff Creem
2000-02-14  0:00 ` Matthew Heaney [this message]
2000-02-14  0:00 ` Tucker Taft
2000-02-15  0:00   ` Robert Dewar
2000-02-15  0:00     ` Tucker Taft
replies disabled

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