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: Larry Coon Subject: Re: Array of tasks Date: 1997/12/09 Message-ID: <348DD9B5.11CD@assist.org>#1/1 X-Deja-AN: 296753265 References: <348D7832.27A4@assist.org> <348DC3C0.7555@gsfc.nasa.gov> Organization: University of California Reply-To: larry@assist.org Newsgroups: comp.lang.ada Date: 1997-12-09T00:00:00+00:00 List-Id: 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