From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: question about tasks, multithreading and multi-cpu machines
Date: Thu, 16 Mar 2006 11:04:34 +0100
Date: 2006-03-16T11:04:34+01:00 [thread overview]
Message-ID: <44193832.1070702@mailinator.com> (raw)
In-Reply-To: <dvapg6$g09$02$2@news.t-online.com>
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.
next prev parent reply other threads:[~2006-03-16 10:04 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-14 16:26 question about tasks, multithreading and multi-cpu machines Norbert Caspari
2006-03-14 16:51 ` Pascal Obry
2006-03-16 4:27 ` Norbert Caspari
2006-03-16 10:04 ` Alex R. Mosteo [this message]
2006-03-14 17:18 ` Jean-Pierre Rosen
2006-03-16 4:22 ` Norbert Caspari
2006-03-16 6:58 ` Jean-Pierre Rosen
2006-03-14 18:49 ` Martin Krischik
2006-03-14 18:56 ` tmoran
2006-03-14 23:01 ` Jeffrey Creem
2006-03-15 1:15 ` Jeffrey R. Carter
2006-03-16 8:06 ` Maciej Sobczak
2006-03-16 10:23 ` Ole-Hjalmar Kristensen
2006-03-16 12:59 ` Dmitry A. Kazakov
2006-03-16 15:11 ` Larry Kilgallen
2006-03-16 15:50 ` Maciej Sobczak
2006-03-16 18:03 ` Jean-Pierre Rosen
2006-03-16 20:06 ` Dr. Adrian Wrigley
2006-03-17 3:26 ` Randy Brukardt
2006-03-16 20:06 ` Jeffrey R. Carter
2006-03-17 8:22 ` Maciej Sobczak
2006-03-17 11:36 ` Dmitry A. Kazakov
2006-03-17 14:23 ` Maciej Sobczak
2006-03-17 19:10 ` Dmitry A. Kazakov
2006-03-17 19:42 ` Jeffrey R. Carter
2006-03-18 0:27 ` tmoran
2006-03-25 21:28 ` Robert A Duff
[not found] ` <43gb22h4811ojjh308r2lqf5qqrujijjok@4ax.com>
2006-03-26 0:44 ` Robert A Duff
2006-03-15 6:46 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox