1

I am an absolute beginner with Ada, and there's one thing I cannot find a concrete definition for - that's the statement entry.

I understand an entry with a barrier - if the barrier is true, the statement can execute and if false, the task is queued until it's evaluated to be true.

For example:

entry Get(Item : out Data_Item) when Number_In_Buffer /= 0 is
begin
...
end Get;

But what does it mean for the statement entry to appear without a following when statement?

User9123
  • 29
  • 1
  • 2

2 Answers2

4

ARM9.4 describes protected objects, which is where entry bodies (as in your code) occur.

It’s not clear from your question, but I think you’re describing a protected specification, with an entry declaration.

Declaration:

protected type Resource is
   entry Seize;
   procedure Release;
private
   Busy : Boolean := False;
end Resource;

Corresponding body:

protected body Resource is
   entry Seize when not Busy is
   begin
      Busy := True;
   end Seize;

   procedure Release is
   begin
      Busy := False;
   end Release;
end Resource;

It is not the caller’s business how the entry is guarded, just that it is. One thing that’s caught me out a couple of times is that an entry body must have a guard; there are some circumstances (requeueing - search the Ada 95 Rationale II.9 for protected Event) where when True is OK.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • 2
    @User9123 To add to Simon's explanation, you appear to be unclear about the differences between a the specification for a protected object and the body of the protected object. The guard is only in the body, not in the specification. – Jim Rogers May 31 '17 at 04:24
0

An ENTRY is also a connection point for TASK communication. In the TASK definition, it is ENTRY. In the TASK BODY, it is an ACCEPT statement. So every ENTRY in a TASK definition has a corresponding ACCEPT in the TASK body.

Jack
  • 5,801
  • 1
  • 15
  • 20
  • 2
    Not strictly true, though probably indicates a mistake. GNAT will warn you about this (you may have to give the right options, `-gnatwa`, I think). It is true that each `accept` in the body has to have a corresponding `entry` in the spec. – Simon Wright May 31 '17 at 07:29