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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: nobody@REPLAY.COM (Anonymous) Subject: Re: Array of tasks Date: 1997/12/10 Message-ID: <199712101557.QAA19627@basement.replay.com>#1/1 X-Deja-AN: 296938562 References: <348D7832.27A4@assist.org> Organization: Replay and Company UnLimited Mail-To-News-Contact: postmaster@nym.alias.net X-001: Replay may or may not approve of the content of this posting X-002: Report misuse of this automated service to X-URL: http://www.replay.com/remailer/ Newsgroups: comp.lang.ada Date: 1997-12-10T00:00:00+00:00 List-Id: On Tue, 09 Dec 1997 08:56:18 -0800, Larry Coon 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/