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-15 15:03:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newscon02.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr14.news.prodigy.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Parallel Merge Sort References: X-Newsreader: Tom's custom newsreader Message-ID: <0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com> NNTP-Posting-Host: 64.175.241.227 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr14.news.prodigy.com 1013814140 ST000 64.175.241.227 (Fri, 15 Feb 2002 18:02:20 EST) NNTP-Posting-Date: Fri, 15 Feb 2002 18:02:20 EST Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: SCSYASVGXZUWSVPXN[O@_WH@YR_B@EXLLBWLOOAFMASJETAANVW[AKWZE\]^XQWIGNE_[EBL@^_\^JOCQ^RSNVLGTFTKHTXHHP[NB\_C@\SD@EP_[KCXX__AGDDEKGFNB\ZOKLRNCY_CGG[RHT_UN@C_BSY\G__IJIX_PLSA[CCFAULEY\FL\VLGANTQQ]FN Date: Fri, 15 Feb 2002 23:02:20 GMT Xref: archiver1.google.com comp.lang.ada:20064 Date: 2002-02-15T23:02:20+00:00 List-Id: > - 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.