From: "fabio de francesco" <fmdf@tiscali.it>
Subject: [newbie question] tasks and protected types
Date: 28 Apr 2005 21:04:17 -0700
Date: 2005-04-28T21:04:17-07:00 [thread overview]
Message-ID: <1114747457.868019.93210@f14g2000cwb.googlegroups.com> (raw)
Hello,
It's the first time I have something to do with protected types and
tasks, so please forgive this newbie question.
The problem is that I have the following program that compiles without
errors but that must have some logical errors. When it is run, it hangs
endlessy. I have only copied the relevant part omitting what is
unneeded to this discussion, anyway it can be compiled without syntax
errors.
First please let me explain what I wanted it to do. I want two
concurrent tasks to get some numbered "tickets" at random intervals.
Each different "ticket" number must be given to each task without
duplication. Every time a task is provided with "ticket" the name of
the task itself and the number is showed. This is like a bank with two
doors assigning numbered tickets to entering customers in order to be
later served at the counter by showing tickets representing order of
arrival.
So I wanted to create two tasks (D1, D2) that wait to be activated with
"Start()". Each of them ask the protected object for a number at random
intervals and then show it with "Put()".
I am not even sure if it is the correct logical implementation. Please,
let me know what I am missing. I apologize you all if my poor English
prevented proper explanation of this issue.
Regards,
fmdf
-- manage.adb
with Ada.Text_IO, Ada.Numerics.Float_Random;
use Ada.Text_IO, Ada.Numerics.Float_Random;
procedure Manage is
protected Tickets is
procedure Assign(New_Value: out Positive);
private
Data: Integer := 0;
end Tickets;
protected body Tickets is
procedure Assign(New_Value: out Positive) is
begin
Data := Data + 1;
New_Value := Data;
end Assign;
end Tickets;
G : Generator;
task type Door is
entry Start( Str : in String; Tm : in Positive );
end Door;
task body Door is
Msg : String := "";
Val : Positive;
Times : Positive;
begin
accept Start( Str : in String; Tm : in Positive ) do
Msg := Str;
Times := Tm;
end Start;
for I in 1..Times loop
delay( Duration( Random( G ) ) );
Tickets.Assign( Val );
Put( Msg & " counts " & Natural'Image( Val ) );
Flush;
end loop;
end Door;
D1 : Door;
D2 : Door;
begin
Reset( G );
D1.Start( "Task 1", 6 );
D2.Start( "Task 2", 6 );
end Manage;
next reply other threads:[~2005-04-29 4:04 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-29 4:04 fabio de francesco [this message]
2005-04-29 7:25 ` [newbie question] tasks and protected types tmoran
2005-04-29 9:43 ` Jacob Sparre Andersen
2005-04-29 10:34 ` Alex R. Mosteo
2005-04-29 11:23 ` Jacob Sparre Andersen
2005-04-29 12:18 ` Adrien Plisson
2005-04-29 12:45 ` Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types) Jacob Sparre Andersen
2005-04-29 13:22 ` Poul-Erik Andreasen
2005-04-29 14:26 ` Egil H. H�vik
2005-04-29 20:28 ` Jacob Sparre Andersen
2005-04-29 20:39 ` Randy Brukardt
2005-04-29 21:23 ` Lionel Draghi
2005-04-29 22:11 ` fabio de francesco
2005-04-30 3:45 ` Jeffrey Carter
2005-04-30 7:21 ` Lionel Draghi
2005-05-02 8:11 ` Jean-Pierre Rosen
2005-04-30 12:47 ` Ada.Text_IO and protected objects Stephen Leake
2005-04-29 21:57 ` Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types) fabio de francesco
2005-04-30 9:07 ` Ada.Text_IO and protected objects Jacob Sparre Andersen
2005-04-30 10:21 ` Dmitry A. Kazakov
2005-05-02 10:41 ` fabio de francesco
2005-05-02 14:10 ` Jacob Sparre Andersen
2005-05-02 16:29 ` fabio de francesco
2005-04-29 15:23 ` Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types) Björn Lundin
2005-04-29 12:54 ` [newbie question] tasks and protected types Alex R. Mosteo
2005-04-29 10:47 ` fabio de francesco
2005-04-29 11:33 ` Jacob Sparre Andersen
2005-04-29 12:55 ` Alex R. Mosteo
2005-04-29 14:06 ` Egil H. H�vik
2005-04-29 14:12 ` Egil H. H�vik
2005-04-29 16:23 ` Robert A Duff
2005-04-29 20:19 ` Jacob Sparre Andersen
2005-04-30 11:58 ` 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