comp.lang.ada
 help / color / mirror / Atom feed
From: nobody@REPLAY.COM (Anonymous)
Subject: Re: Array of tasks
Date: 1997/12/10
Date: 1997-12-10T00:00:00+00:00	[thread overview]
Message-ID: <199712101557.QAA19627@basement.replay.com> (raw)
In-Reply-To: 348D7832.27A4@assist.org


On Tue, 09 Dec 1997 08:56:18 -0800, Larry Coon <larry@assist.org> wrote:

> I posted a similar question from home a few days ago,
> and didn't see a response.  I checked from work and
> didn't see my original question, so I'm posting again
> just in case something happened to my original post.
> My apologies if you've already seen this.
> 
> I have an array of tasks and an array of semaphores.
> The size of both arrays are set at runtime (based on
> user input).  I can't figure out a way to make the
> array of semaphores visible to the array of tasks.
> 
> Here's some contrived code to illustrate what I'm
> trying to do:
> 
> procedure main is
>   protected type semaphore is
>     entry seize;
>     procedure release;
>   private
>     available:	boolean := true;
>   end semaphore;
> 
>   -- The usual implementation of a semaphore.
>   protected body semaphore is separate;
> 
>   task type t;
>   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;
> 
> Within the body of task T I want to access a semaphore in
> semaphore_array.  It won't compile, saying the semapore
> array is not visible.
> 
> How do I declare things so the tasks can see the semaphores?
> I've tried nested blocks, and I've tried passing pointers
> to the semaphores, but couldn't get anything to work right.
> Thanks in advance for any help.
> 

The body of type T comes before the declaration of the array of
Semaphore_Array, so it should not be surprising that Semaphore_Array is
not visible in the body of T.

The simple solution is to move the definition of T into the block, so
the body comes after the declaration of Semaphore_Array. Of course, this
means the body of T cannot be separate.

A more complicated solution gives T an access discriminant to type
Semaphore. Then the body of T refers to the semaphore designated by this
access value, not to the array. The fun part is giving each task its own
semaphore access value.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/































  parent reply	other threads:[~1997-12-10  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
1997-12-10  0:00     ` Mats Weber
1997-12-10  0:00 ` Anonymous [this message]
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