comp.lang.ada
 help / color / mirror / Atom feed
* RE: Protected Type Question.
@ 2000-12-12  6:43 Beard, Frank
  0 siblings, 0 replies; 12+ messages in thread
From: Beard, Frank @ 2000-12-12  6:43 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

The task (3) combination was more common, but I also had other
task combinations hang.  I don't think the program is crashing.
Each of the tasks have "when others" exception handlers that log,
and nothing is showing up.

Pragma Atomic and Volatile were a shot in the dark.  I didn't 
really think it would make a difference.

We're running on NT 4.0 with Service Pack 5.

If you think of anything else, let me know.
Thanks.

Frank

-----Original Message-----
From: tmoran@acm.org [mailto:tmoran@acm.org]
Sent: Monday, December 11, 2000 10:40 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Protected Type Question.


That semaphore code should work, and certainly shouldn't hang.  Is there
any possible significance to the fact both your examples show task (3)
as the one that does a RELEASE but never gets to RELEASED?  Are you
sure the program is hanging, and not crashing and somehow hanging
during the attempted crash?
  Pragmas Atomic and Volatile should certainly not be necessary.  The
whole point is that only one task at a time can execute the entries
or procedures in, and thus access or change the value of data
(Busy, in this case) of, a protected object.
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




^ permalink raw reply	[flat|nested] 12+ messages in thread
* protected type question
@ 2004-01-03 20:58 shoko
  2004-01-04  0:50 ` James Rogers
  2004-01-04  1:04 ` Robert I. Eachus
  0 siblings, 2 replies; 12+ messages in thread
From: shoko @ 2004-01-03 20:58 UTC (permalink / raw)


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");
  
   TASK messages;
   
   task body messages is
      m:message;
   begin
      loop
          str_broadcasts.wait(a);<-- compilation error
      end loop;   
   end messages;
begin
   
   null;
end main_broadcast;



^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: Protected Type Question.
@ 2000-12-13 23:23 Beard, Frank
  0 siblings, 0 replies; 12+ messages in thread
From: Beard, Frank @ 2000-12-13 23:23 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

I took Robert's advice and changed the Delete
and New_String methods back to protected
operations, and the program no longer hangs.

Frank

-----Original Message-----
From: Robert Dewar [mailto:robert_dewar@my-deja.com]

>  18   Certain language-defined subprograms are potentially
>  blocking.  ... When not specified as potentially blocking,
>  a language-defined subprogram is nonblocking.
>
>Unchecked_Deallocation is not specified as potentially blocking.
>





^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: Protected Type Question.
@ 2000-12-12  5:49 Beard, Frank
  2000-12-12 10:54 ` Robert Dewar
  0 siblings, 1 reply; 12+ messages in thread
From: Beard, Frank @ 2000-12-12  5:49 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

> One of the other dangers of semaphores
> is that you can forget to claim or release, causing
> chaos, or indeed forget both, resulting in race
> conditions. By synchronizing at a higher
> structural level, these dangers are avoided.

I'm well aware of the danger, and I totally
agree that when at all possible the synchronization
should be done at a higher level.  That's exactly
the way it is done in other parts of our code.
The only reason I'm trying the "semaphore" approach
here is I was told on the ObjectAda list-server that
Unchecked_Deallocation is potentially blocking,
so it shouldn't be called from within a protected
type.  Delete and New_String used to be protected
operations.  The Delete code contains calls to a
garbage collector (with a limit).  When the limit
is reached, Unchecked_Deallocation is called.
If it is true, that it is potentially blocking,
then I have to go with the "semaphore" 
approach, or use another task (which I was
trying to avoid).

Is Unchecked_Deallocation, or "new" for that
matter, potentially blocking?

> I just made the
> technical comment that semaphores are NOT the
> preferred form of task synchronization these
> days, and to use protected types to implement
> semaphores is definitely an example of
> abstraction inversion. These are hardly
> contentious points of view :-)

I'm not trying to use semaphores for task
synchronization in the classic sense, only to
protect the garbage collector.  The tasks pass
messages through the system using protected queues.
The Get and Put methods are protected operations.
The Input task receives a message, parses it, determines
where it goes, and places it on the respective 
protected queue.  Each of the different processing
tasks handle a different type of message.  If
any of the processing tasks determine that a
message contains errors, they place the erred message
on the protected Error_Queue for the Error_Task.
The Error_Task interacts with a special table in the
database where messages are corrected by an operator
through a GUI and sent back into the system.
Once an erred message is corrected it is processed
or placed on the Output_Buffer where the Output_Task
sends it back out through the network.

It just so happens that every task in the system,
either directly or through calls to other classes,
uses the Byte_String_Class to build or process
the message objects that also happens to contain
byte strings as components.  Byte_String_Class is
just a class that contains a Byte_String_Object
which is just a fancy pointer to a Byte_Array
that is used for all kinds of stuff.  The same
way you would use Ada.Strings.Unbounded
Unbounded_String.  It just happens to also be
a component of the message object.

And before anyone asks why we are not using
Unbounded_String, it is because we are trying to
figure out why Unbounded_String started failing.
Unbounded_Strings are released by setting them
to Null_String.  There was no protected type 
involved (unless Unbounded_String is also a
protected type).  The tasks were using the
Unbounded_Strings, then setting them to Null_String.
Somewhere along the line, after running for a
long time, the Unbounded_Strings suddenly have
residual data in them, as if the memory was 
picked up before the runtime cleared it.
So, I was looking for a way to switch to our
dynamic string class, which I know needs 
protection.

I hope this makes things clearer.
Any help is greatly appreciated.

Frank




^ permalink raw reply	[flat|nested] 12+ messages in thread
[parent not found: <B6A1A9B09E52D31183ED00A0C9E0888C46992F@nctswashxchg.nctswash.navy.mil>]
* RE: Protected Type Question.
@ 2000-12-12  1:45 Beard, Frank
  2000-12-12  2:51 ` Robert Dewar
  0 siblings, 1 reply; 12+ messages in thread
From: Beard, Frank @ 2000-12-12  1:45 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Robert,

Am I supposed to say thanks for this?

Since the only positive statement was
"Certainly this should work fine", I
guess I'm compelled to follow it up
with some questions since you didn't
offer anything more useful.

Concerning your comment
"and is very poor programming style".
Since it is taken directly from the LRM,
are you saying the LRM is written in
poor programming style?  The fact that I
split it into a package spec and body
is poor programming style?  Elaborate
please.

Concerning, "though of course no one would
use it in the form given (it is obviously
subject to priority inversion".  Our system
is a message correction system that is not
required to be real-time, other than it can't
be too slow.  All our tasks are at the same
priority so there isn't any inversion.  But
for argument's sake, lets say I need this type
of "semaphore" for protecting critical regions
within a system that contains prioritized tasks.
What would be your suggestion for "correcting"
the form so that is not subject to priority
inversion and bad programming style? 

I usually go out of my way to give someone
something useful.  I haven't done it much 
here yet because I'm new to the list.  But,
it rubs me the wrong way to get an answer
that is not only terse, but somewhat
condescending as well.  If you're going to
make such statements, offer a solution.
Something positive.  A way to correct it.
"Here's a better way".  Something.

I don't want insults, I want assistance.  If
I can offer something to someone less 
experienced or less knowledgeable, I try to do
so, and hopefully with a little more mercy.

Anyone can say something is lousy, but few
can offer a better way.  Which one are you?
Which one do you want to be?

If bashing is what I want, I'll become a C++
programmer and slam Ada for no good reason.

Frank

PS.
If that's not the way you meant your response,
I take it all back. ;-)

-----Original Message-----
From: Robert Dewar [mailto:robert_dewar@my-deja.com]
Sent: Monday, December 11, 2000 10:57 AM
To: comp.lang.ada@ada.eu.org
Subject: Re: Protected Type Question.

Certainly this should work fine, though of course no one would
use it in the form given (it is obviously subject to priority
inversion, and is very poor programming style).


Sent via Deja.com http://www.deja.com/
Before you buy.
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Protected Type Question
@ 1996-03-20  0:00 Bill Pritchett
  1996-03-20  0:00 ` Robert Dewar
  0 siblings, 1 reply; 12+ messages in thread
From: Bill Pritchett @ 1996-03-20  0:00 UTC (permalink / raw)


I have a question regarding protected types.  Specifically, I've been trying to figure out
how to pin a protected object to a specific memory location.  The two ways I have tried are as 
follows:

  procedure Test is

    protected type Sensor (Sensor_Address : System.Address) is
      function Get_Value return Integer;
    private
      The_Sensor : Integer;
      for The_Sensor'Address use Sensor_Address;
    end Sensor;
    ...
    Sensor1 : Sensor(..);
  begin
    ...
  end Test;

GNAT bombs on this incorrectly stating 'missing "end Sensor"' which throws the rest of the 
compilation out of whack.  I'm pretty sure this is NOT legal anyway.

The second alternative is this

  procedure Test is

     protected type Sensor is
       function Get_Value return Integer;
     private
       The_Sensor : Integer;
     end Sensor;
     ...
     Sensor1 : Sensor;
     for Sensor1'Address use ...;

  begin
   ...
  end Test;

This compiles.  When I execute this it bombs (partly because I have no clue of what's at the 
address I give it).  My question is what does the address (Sensor1'Address) represent?  Is it the 
address to the object as a whole or to The_Sensor (what I want)?  If it is to the object as a 
whole, then how does one specify a particular address for a protected object?  Is it possible 
directly?

Thanks,
Bill Pritchett
CACI, Inc.




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

end of thread, other threads:[~2004-01-04  1:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-12  6:43 Protected Type Question Beard, Frank
  -- strict thread matches above, loose matches on Subject: below --
2004-01-03 20:58 protected type question shoko
2004-01-04  0:50 ` James Rogers
2004-01-04  1:04 ` Robert I. Eachus
2000-12-13 23:23 Protected Type Question 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

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