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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,86cefd3e84a541f2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-16 03:15:05 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!194.25.134.62!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!amsnews01.chello.com!surfnet.nl!star.cs.vu.nl!not-for-mail From: "R. Stegers" Newsgroups: comp.lang.ada Subject: Re: Parallel Merge Sort Date: Sat, 16 Feb 2002 12:09:18 +0100 Organization: Fac. Wiskunde & Informatica, VU, Amsterdam Message-ID: References: <0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com> NNTP-Posting-Host: kits.cs.vu.nl X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Xref: archiver1.google.com comp.lang.ada:20076 Date: 2002-02-16T12:09:18+01:00 List-Id: Thanks a lot, this is exactly what I needed to know! schreef in bericht news:0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com... > > - How can I dynamicaly allocate a temporary array (for which i don't know > > the size in advance?) It seems inpossible to me. > > - How to create tasks from within a task: The subTask1 en subTask2 > > declarations generate errors: "Task type cannot be used as type mark within > > its own body" > > Consider what would happen if you created an object of type MergeSortTask > where: > > task body MergeSortTask is > > subTask1 : MergeSortTask; > > subTask2 : MergeSortTask; > > begin > > ... > That object will require creation of two more MergeSortTasks, each of > which will create two more ..., all before you've even found out if there's > any data to sort. So you will have to create the subtasks dynamically. > type Pointer_To_MergeSortTask is access MergeSortTask; > task body MergeSortTask is > subTask1 : Pointer_To_MergeSortTask; > subTask2 : Pointer_To_MergeSortTask; > begin > ... > if (**array size > 1 element**) > -- Actually sort the array here > subTask1 := new MergeSortTask; > subTask2 := new MergeSortTask; > subTask1.doSort(**<1st half>**); > subTask2.doSort(**<2nd half>**); > > -- Wait till both sub-task have finished sorting > subTask1.awaitResult; > subTask2.awaitResult; > > > > accept doSort(InArray : in out element_array) do > > ** How to get the InArray to be used outside the doSort?? ** > > -- Synchronize with the caller but return control > > end doSort; > You'll have to copy InArray, since you only have access to it for > the (short) time you are between the "accept" and the "end doSort". > You can't create the copy on the stack "Copy : element_array := InArray;" > since of course the stack is cut back at "end doSort", so you'll have > to create the copy on the heap and manually free it. > type Pointer_To_Element_Array is access Element_Array; > ... > -- then inside the task body: > My_Data : Pointer_To_Element_Array; > ... > accept doSort(InArray : in out element_array) do > -- Create a local copy of InArray on the heap > My_Data := new Element_Array'(InArray); > -- Synchronize with the caller but return control > end doSort; > > But this is not what you want, of course, since it does not sort > InArray, but only a copy of it. In particular, the code > baseTask.doSort(InArray); > won't sort InArray - it will merely start up, and not wait for, a > set of tasks that will sort a copy of InArray. One possible solution > is to make > entry doSort (InArray : in element_array); > entry awaitResult(InArray : out element_array); > and return the sorted result at awaitResult time.