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,c3c4ae45442f569e,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "fabio de francesco" Newsgroups: comp.lang.ada Subject: [newbie question] tasks and protected types Date: 28 Apr 2005 21:04:17 -0700 Organization: http://groups.google.com Message-ID: <1114747457.868019.93210@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: 80.181.52.213 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1114747463 9107 127.0.0.1 (29 Apr 2005 04:04:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 29 Apr 2005 04:04:23 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=80.181.52.213; posting-account=Lp02jQ0AAABMd3TAghNf0TM2YBZqD_JE Xref: g2news1.google.com comp.lang.ada:10800 Date: 2005-04-28T21:04:17-07:00 List-Id: 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;