comp.lang.ada
 help / color / mirror / Atom feed
* Tasks problem
@ 2003-12-19 17:03 Ratson Janiv
  2003-12-19 18:45 ` Martin Dowie
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ratson Janiv @ 2003-12-19 17:03 UTC (permalink / raw)


Hi,
I have a task T_Check that checks if a number is a prime one.
I have a task T_Manager that manages the checks.
In T_Manager I have an array of T_Check(1..N).

Now, lets say I want the T_Manager task to check the numbers 1..100 if they
are prime.
I have only 8 T_Checks tasks (N=6).
How do I manage the tasks allocations ?
I thought about T_Manager getting a notification from T_Check when it
finishes checking, and when T_Manager is notified it shold recall the Check
entry in the T_CHeck task that notified it.
The problem is that I dont know how to know which task (T_Check) amongst the
Nth tasks has notified me.
Is there any solution in ADA?
Maybe my solution is not so good (Hellllllloooooooooo?), what is the
solution U may suggest me ?

Thanks a lot,
Janiv Ratson.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Tasks problem
@ 2003-12-19 17:55 Mr. J.
  0 siblings, 0 replies; 5+ messages in thread
From: Mr. J. @ 2003-12-19 17:55 UTC (permalink / raw)


Hi,
I have a task T_Check that checks if a number is a prime one.
I have a task T_Manager that manages the checks.
In T_Manager I have an array of T_Check(1..N).

Now, lets say I want the T_Manager task to check the numbers 1..100 if they
are prime.
I have only 8 T_Checks tasks (N=6).
How do I manage the tasks allocations ?
I thought about T_Manager getting a notification from T_Check when it
finishes checking, and when T_Manager is notified it shold recall the Check
entry in the T_CHeck task that notified it.
The problem is that I dont know how to know which task (T_Check) amongst the
Nth tasks has notified me.
Is there any solution in ADA?
Maybe my solution is not so good (Hellllllloooooooooo?), what is the
solution U may suggest me ?

Thanks a lot,
Janiv Ratson.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Tasks problem
  2003-12-19 17:03 Tasks problem Ratson Janiv
@ 2003-12-19 18:45 ` Martin Dowie
  2003-12-20  1:57 ` Stephen Leake
  2003-12-20  3:07 ` Steve
  2 siblings, 0 replies; 5+ messages in thread
From: Martin Dowie @ 2003-12-19 18:45 UTC (permalink / raw)


"Ratson Janiv" <janiv@013.net.il> wrote in message
news:3fe32ff4$1@news.barak.net.il...
> Hi,
> I have a task T_Check that checks if a number is a prime one.
> I have a task T_Manager that manages the checks.
> In T_Manager I have an array of T_Check(1..N).
>
> Now, lets say I want the T_Manager task to check the numbers 1..100 if
they
> are prime.
> I have only 8 T_Checks tasks (N=6).
> How do I manage the tasks allocations ?
> I thought about T_Manager getting a notification from T_Check when it
> finishes checking, and when T_Manager is notified it shold recall the
Check
> entry in the T_CHeck task that notified it.
> The problem is that I dont know how to know which task (T_Check) amongst
the
> Nth tasks has notified me.
> Is there any solution in ADA?
> Maybe my solution is not so good (Hellllllloooooooooo?), what is the
> solution U may suggest me ?

You could use a rendezvous - how else were you going to return the result to
T_Manager?

subtype Check_Index is Integer range 1 .. 6; -- or '8'???

task T_Manager is
-- No need for a task type if you are only going to have one of them
   ...
   accept Notify (Index : Check_Index; N : Integer; Is_Prime : Boolean);
   ...
end T_Manager;

task type T_Check (Index : Check_Index) is
-- Any other task entries
   ...
   entry Check (N : Integer);
   ...
end T_Check;

task body T_Manager is
   Next_Number_To_Check : Integer := 1;
begin
   -- Allocate the checking
end T_Manager;

task body T_Check is
   function Check_If_Prime (I : Integer) return Boolean is
   begin
      return ...;
   end Check_If_Prime;

   Number : Integer;
   Is_Prime : Boolean;
begin
   ...
   accept Check (N : Integer) do
      Number := N;
   end Check;
   ...
   Is_Prime := Check_If_Prime (Number);
   ...
   T_Manager.Notify (Index, Number, Is_Prime);
   ...
end T_Check;





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Tasks problem
  2003-12-19 17:03 Tasks problem Ratson Janiv
  2003-12-19 18:45 ` Martin Dowie
@ 2003-12-20  1:57 ` Stephen Leake
  2003-12-20  3:07 ` Steve
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2003-12-20  1:57 UTC (permalink / raw)
  To: comp.lang.ada

"Ratson Janiv" <janiv@013.net.il> writes:

> The problem is that I dont know how to know which task (T_Check) amongst the
> Nth tasks has notified me.

Assign each task an ID, pass that ID along with the notification.

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Tasks problem
  2003-12-19 17:03 Tasks problem Ratson Janiv
  2003-12-19 18:45 ` Martin Dowie
  2003-12-20  1:57 ` Stephen Leake
@ 2003-12-20  3:07 ` Steve
  2 siblings, 0 replies; 5+ messages in thread
From: Steve @ 2003-12-20  3:07 UTC (permalink / raw)


I would probably take a slightly different approach.  I would use a
protected object to keep track of the highest number checked.

The tasks would be declared as an array inside of a procedure (after the
protected object).

Each task would get the next number to evaluate from a protected procedure
inside the protected object.  The protected procedure would return a number
to evaluate and a flag indicating when all evaluations are done.  The tasks
would terminate when there are no new numbers to check.  The containing
procedure would return automagically when all tasks in the array are
terminated.

This technique does not use a task to "manage" each of the n tasks, they
essentially manage themselves.

Steve
(The Duck)

"Ratson Janiv" <janiv@013.net.il> wrote in message
news:3fe32ff4$1@news.barak.net.il...
> Hi,
> I have a task T_Check that checks if a number is a prime one.
> I have a task T_Manager that manages the checks.
> In T_Manager I have an array of T_Check(1..N).
>
> Now, lets say I want the T_Manager task to check the numbers 1..100 if
they
> are prime.
> I have only 8 T_Checks tasks (N=6).
> How do I manage the tasks allocations ?
> I thought about T_Manager getting a notification from T_Check when it
> finishes checking, and when T_Manager is notified it shold recall the
Check
> entry in the T_CHeck task that notified it.
> The problem is that I dont know how to know which task (T_Check) amongst
the
> Nth tasks has notified me.
> Is there any solution in ADA?
> Maybe my solution is not so good (Hellllllloooooooooo?), what is the
> solution U may suggest me ?
>
> Thanks a lot,
> Janiv Ratson.
>
>
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-12-20  3:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-19 17:03 Tasks problem Ratson Janiv
2003-12-19 18:45 ` Martin Dowie
2003-12-20  1:57 ` Stephen Leake
2003-12-20  3:07 ` Steve
  -- strict thread matches above, loose matches on Subject: below --
2003-12-19 17:55 Mr. J.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox