From: James Rogers <jimmaureenrogers@att.net>
Subject: Re: protected type question
Date: Sun, 04 Jan 2004 00:50:28 GMT
Date: 2004-01-04T00:50:28+00:00 [thread overview]
Message-ID: <Xns9465B5539DC6jimmaureenrogers@204.127.36.1> (raw)
In-Reply-To: 4948f537.0401031258.62a7cdc7@posting.google.com
shoko2004@hotmail.com (shoko) wrote in
news:4948f537.0401031258.62a7cdc7@posting.google.com:
> i have the following package:
>
> generic
> type Message is private;
> package Broadcasts is
> protected type Broadcast is
> procedure Send(This_Message : in Message);
> procedure Send_all(This_Message : in Message);
> entry wait(A_Message : out Message );
> private
> Message_Arrived:Boolean:=False;
> The_Message:Message;
> end Broadcast ;
> end Broadcasts ;
> ----------------------------------------------------------------
>
> package body Broadcasts is
> protected body Broadcast is
> entry wait(A_Message : out Message ) when Message_Arrived is
> begin
> if wait'Count=0 then
> Message_Arrived:=False;
> end if;
> A_Message:=The_Message;
> end wait;
>
> procedure Send (This_Message : in Message ) is
> begin
> if wait'Count>0 then
> Message_Arrived:=True;
> The_Message:=This_Message;
> end if;
> end Send;
>
> procedure send_all(This_Message : in Message )is
> begin
> Message_Arrived:=True;
> The_Message:=This_Message;
> end send_all;
> end Broadcast ;
> end Broadcasts;
> ----------------------------------------------------------------
>
> in the main procedure i am trying to create a task
> 1.I get compiltaion error:"wait" not decllared in "str_broadcasts"
> what am i doing wrong?
>
> 2.In the broadcasts package i use send all procedure that will free
> all waiting tasks is this is the right way?
>
>
>
> with broadcasts;
> with Ada.Strings.Unbounded;
> use Ada.Strings.Unbounded;
>
> procedure main_broadcast is
>
> subtype message is Unbounded_String;
> package str_broadcasts is new broadcasts(message);
> a:message :=To_Unbounded_String("hello");
buffer : str_broadcasts.broadcast;
>
> TASK messages;
>
> task body messages is
> m:message;
> begin
> loop
> str_broadcasts.wait(a);<-- compilation error
buffer.wait(a);
> end loop;
> end messages;
> begin
>
> null;
> end main_broadcast;
>
str_broadcasts is the name of the instantiated package.
str_broadcasts.broadcast is the name of the protected
type. You need to make an instance of that protected
type. My addition creates an instance named "buffer".
Jim Rogers
next prev parent reply other threads:[~2004-01-04 0:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-03 20:58 protected type question shoko
2004-01-04 0:50 ` James Rogers [this message]
2004-01-04 1:04 ` Robert I. Eachus
-- strict thread matches above, loose matches on Subject: below --
2000-12-13 23:23 Protected Type Question Beard, Frank
2000-12-12 6:43 Beard, Frank
2000-12-12 5:49 Beard, Frank
2000-12-12 10:54 ` Robert Dewar
[not found] <B6A1A9B09E52D31183ED00A0C9E0888C46992F@nctswashxchg.nctswash.navy.mil>
2000-12-12 3:39 ` tmoran
2000-12-12 1:45 Beard, Frank
2000-12-12 2:51 ` Robert Dewar
1996-03-20 0:00 Bill Pritchett
1996-03-20 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox