From: anon@anon.org (anon)
Subject: Re: Task question
Date: Tue, 11 Dec 2007 00:43:41 GMT
Date: 2007-12-11T00:43:41+00:00 [thread overview]
Message-ID: <13l7j.238158$kj1.79368@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 31235206-1025-467c-8444-07a8eacc9b48@e6g2000prf.googlegroups.com
--
-- f_p.adb
--
with Ada.Text_IO ;
procedure F_P is
task type Function_Task is
entry Function_1 ( X : in Boolean ) ;
entry Result_1 ( X : out Boolean ) ;
end function_Task ;
--
-- This task uses two calls. One activate the function
-- and the second returns the function value once valid.
--
-- Note: Delays are use to simulate the actual algorithm for
-- the function. Normally there are not needed.
--
task body Function_Task is
W : Boolean ; -- Hold paramter and result value
begin -- Function_Task
-- Initial or setup functions
loop
select
--
-- Start execution of function
--
accept Function_1 ( X : in Boolean ) do
W := X ;
end Function_1 ;
--
-- Routine for function. It could be a function call
-- Or code here
--
Delay 1.0 ; -- simulate a complex algorithm
W := not W ;
or
--
-- Retrieve function's result if needed wait until
-- result is valid
--
accept Result_1 ( X : out Boolean ) do
X := W ; -- Retrive result.
end Result_1 ;
or
--
-- Allows the task to end, if the program exist
--
terminate ;
end select ;
end loop ;
-- shutdown function
end function_Task ;
procedure put ( V : boolean ) is
begin
if V then
Ada.Text_IO.put ( Item => "True" ) ;
else
Ada.Text_IO.put ( Item => "False" ) ;
end if ;
end ;
Functions : function_Task ;
Z : Boolean := True ;
begin -- F_P
Ada.Text_IO.put_line ( Item => "Excute Function 1" ) ;
Functions.Function_1 ( Z ) ;
Put ( Z ) ;
Ada.Text_IO.new_line ;
Ada.Text_IO.put_line ( Item => "Excute Something Else" ) ;
--
-- Now we need the result from Function 1. So we may
-- need to wait until result of function is valid.
--
Ada.Text_IO.put_line ( Item => "Get Result for function 1" ) ;
Functions.Result_1 ( Z ) ;
Put ( Z ) ;
Ada.Text_IO.new_line ;
Ada.Text_IO.put_line ( Item => "Exit Program" ) ;
end F_P ;
In <31235206-1025-467c-8444-07a8eacc9b48@e6g2000prf.googlegroups.com>, shaunpatterson@gmail.com writes:
>Hey,
>
> What is the best / proper way to spawn a new task so that a
>function call can
>continue in the background.. like so:
>
>procedure Test is
> begin
>
> -- Call a callback function that may take a long time
> FuncPtr.all
>
>
> -- Continue other processing here
>
> end Test;
>
>
>Is there any way to encapsulate the callback function call in another
>task WITHOUT making
>the function -- the function called by funcptr.all -- a new task?
>
>Thanks
>
>--
>Shaun
next prev parent reply other threads:[~2007-12-11 0:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-10 22:12 Task question shaunpatterson
2007-12-10 22:29 ` gpriv
2007-12-10 22:51 ` shaunpatterson
2007-12-10 23:13 ` gpriv
2007-12-10 23:40 ` Robert A Duff
2007-12-11 0:43 ` anon [this message]
-- strict thread matches above, loose matches on Subject: below --
1997-10-16 0:00 Paul Van Gorp
1997-10-19 0:00 ` elaine.waybright
1997-11-01 0:00 ` Matthew Heaney
1997-10-21 0:00 ` Robert A Duff
1997-10-06 0:00 Larry Coon
1997-10-07 0:00 ` Matthew Heaney
1997-10-07 0:00 ` Larry Coon
1997-10-07 0:00 ` David C. Hoos, Sr.
1997-10-07 0:00 ` Larry Coon
1997-10-07 0:00 ` Steve O'Neill
1997-10-08 0:00 ` Matthew Heaney
1997-10-08 0:00 ` Tom Moran
1997-10-07 0:00 ` Robert A Duff
1997-10-13 0:00 ` Larry Coon
1997-10-30 0:00 ` Balmacara9
1996-09-15 0:00 task question Nicolay Belofastow
1996-09-23 0:00 ` Matthew Heaney
[not found] <204266@QZCOM>
1986-09-26 17:28 ` Task question Matts_Kallioniemi_QZ
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox