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,e2e6547249e6f9d1 X-Google-Attributes: gid103376,public From: jsa@alexandria (Jon S Anthony) Subject: Re: How to wait for task completion Date: 1996/09/16 Message-ID: #1/1 X-Deja-AN: 180994734 sender: news@organon.com (news) references: <01bba2e8$c45aad90$35208b82@wd> organization: Organon Motives, Inc. newsgroups: comp.lang.ada Date: 1996-09-16T00:00:00+00:00 List-Id: In article <01bba2e8$c45aad90$35208b82@wd> "wiljan" writes: > Is there a simply way to wait until a task has completed in Ada? > I have a pointer to a task type: > task type tsk; > type ptsk is access tsk; > p:ptsk; > At a certain point I want to clean up the resources that the task is > using but this can only be done when the task is completed. Depending on your needs and constraints, the simplest trick would be: in some code where you require P, ... declare type Ptsk is access Tsk; -- Put access type here to make block master P : Ptsk; ... begin null; end; -- Wait until You can also put the block in another "parent" task to avoid blocking the whole program (if that is desirable and deemed "cheap" enough). For example: with Text_IO; with Objs; use Objs; procedure Wait_Ex is task type Tks; task body Tks is begin for I in 1..20 loop delay 0.1; Text_IO.Put_Line("Hi" & Integer'Image(i)); end loop; end; begin declare type Ptsk is access Tks; T : Ptsk := new Tks; begin null; end; Text_IO.Put_Line("Done"); end Wait_Ex; $ gnatmake wait_ex.adb $ wait_ex.adb Hi 1 Hi 2 Hi 3 Hi 4 Hi 5 Hi 6 Hi 7 Hi 8 Hi 9 Hi 10 Hi 11 Hi 12 Hi 13 Hi 14 Hi 15 Hi 16 Hi 17 Hi 18 Hi 19 Hi 20 Done $ -- Jon Anthony Organon Motives, Inc. 1 Williston Road, Suite 4 Belmont, MA 02178 617.484.3383 jsa@organon.com