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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3f60acc31578c72b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: question about tasks, multithreading and multi-cpu machines Date: Thu, 16 Mar 2006 11:04:34 +0100 Message-ID: <44193832.1070702@mailinator.com> References: <4416F491.6080309@obry.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net V8OmPjGnjiHfkbTlnuZ3QQrGBFZ/tyrmR5O+aRBftSP55FlUw= User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:3377 Date: 2006-03-16T11:04:34+01:00 List-Id: Norbert Caspari wrote: > Pascal Obry wrote: > > >>Use Tasks. > > > Thank you very much for answering my questions. But how can I use > multitasking with Ada? There is no such thing like "fork" available in > this programming language. Multitasking is built-in in the language. Basically, each object of type Task is a new thread of execution. Check some tutorials on Ada tasking for details. Sorry, I don't have references handy. Tasking is an important feature of Ada and so can't be properly explained in a single post. Maybe: http://en.wikibooks.org/wiki/Ada_Programming/Tasking So, in Ada instead of "forking" the current process into two, you simply create a new task. You'll see that Ada tasking features are much more confortable than low-level APIs for multithreading. Two examples: procedure Main is task Second; task body Second is begin loop null; end loop; end Second; begin -- whatever end; Here you have your main task, whose code is in the body of the main procedure, and a second "thread" which is the code inside the body of Second. The Second task starts running during the elaboration (or "loading", if you're not familiar with the elaboration concept) of the main program. Second example: procedure Main is task type Child; -- Note the "type" keyword here, missing in 1st ex. task body Child is begin -- whatever end; type Access_Child is access all Child; C : Access_Child; begin -- some code C := new Child; -- more code end; Here, you have your main task/thread embodied, as before, in the Main procedure. You create a new task/thread with the line C := new Child; and the code inside Child starts running at that point. The difference with the 1st example is that we are declaring a "task type", so no task is created until some object of that type is created. In the first example we directly declared a task object (not type), so the task started to exist right there. Each task has its own stack, but all tasks share the global variables. You can then communicate amongst them with rendez-vous or protected objects.