From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,146880aa5d8c64c7 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Array of tasks Date: 1997/12/09 Message-ID: <348DC3C0.7555@gsfc.nasa.gov>#1/1 X-Deja-AN: 296727220 References: <348D7832.27A4@assist.org> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1997-12-09T00:00:00+00:00 List-Id: Larry Coon wrote: > > 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: > > > > 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. > 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. with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; procedure Test 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; type Semaphore_Array_Type is array (Integer range <> ) of semaphore; type Semaphore_Array_Access_Type is access all Semaphore_Array_Type; task type T (Semaphore_Array : Semaphore_Array_Access_Type); task body t is separate; task_count: positive; begin -- main put ("Enter number of tasks: "); Ada.Integer_Text_IO.get (task_count); declare subtype task_range is integer range 1..task_count; Semaphore_Array : Semaphore_Array_Access_Type (task_range) := new Semaphore_Array_Type (Task_Range); subtype Specific_Task is T (Semaphore_Array); task_array: array (task_range) of Specific_Task; begin null; end; end Test; separate (Test) 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 (Test) task body T is begin Semaphore_Array (1).Seize; end T; > Larry Coon > University of California > larry@assist.org > and lmcoon@home.com -- - Stephe