comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: task question
Date: 1996/09/23
Date: 1996-09-23T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023080002309961904030001@news.ni.net> (raw)
In-Reply-To: 51hg8f$1ei@infosrv.rz.unibw-muenchen.de


In article <51hg8f$1ei@infosrv.rz.unibw-muenchen.de>,
e81bnick@kommsrv.rz.unibw-muenchen.de (Nicolay Belofastow) wrote:

>I am novice in ADA, and  have a question concerning operator
>ACCEPT:

FYI: Ada is not an acronym, it's the name of Ada Lovelace, Charles
Babbage's assistent and the world's first programmer.  In fact, the
original military standard, MIL-STD-1815, is named in honor of the year of
her birth.  So you don't capitalize Ada (or else I think it's a post about
the American Dental Association!).

Also, aviod all-uppercase keywords (and identifiers), as it's hard on the
eyes!  People that study these kinds of things (read Ben Schneiderman's
book) note that humans read mixed case type more easily than all-uppercase. 
It's best to use all-lowercase for keywords, and mixed-case for
identifiers.

Yes, it's true that early Ada textbooks (including the Ada83 LRM) used
all-uppercase type for identifiers, but the Ada community has forsworn that
use in favor of a different idiom.

>
>normal usage would be somewhere in the task body:
>
>accept Entry( Par1 : integer) do 
>  -- some actions here;
>end Entry;
>
>my program with accept, compiled by GNAT 3.04 shows, that body of
>the accept (commented as "some actions") looks like protected 
>section -- before "some action " is not finished, no other task 
>gets control. The question is -- is this standard feature of the
>ADA, or it is only belongs to GNAT or Windows 95?

It is not true that no other task gets control.  In other words, some other
task can get control.  This is  the legal Ada (note capitalization...)
behavior.

It's a common misunderstanding about Ada's tasking rules to think that
during a rendevous the task(s) can't get interrupted.  This is incorrect,
because the tasks participating in the rendevous *can* get interrupted by a
task of higher priority (for example, because an external interrupt occurs
on a task entry).

Of course, the rendevous is still a sort of critical region, and neither
task will handle other entry calls until the rendevous is finished.

I don't have my Ada95 LRM handy, but here's the applicable section of the
Ada83 LRM, section 9.8, paragraph 4:

"The effect of priorities on scheduling is defined by the following rule:

If two tasks with different priorities are both eligible for execution and
could sensibly be executed using the same physical processors and the same
other processing resources, then it cannot be the case that the task with
the lower priority is executing while the task with the higher priority is
not."

Here's what AI-00032 says:

"Preemptive scheduling is required.

If an implementation supports more than one priority level, or interrupts
[interrupts is called out explicitly because the LRM mandates that
interrupts occur at higher-than-normal priorities], then it must also
support a preemptive scheduling policy."

What this is all saying is that while the rendevous is executing, another
task can interrupt the rendevous and grab the CPU.

Try it:

with Text_IO;
procedure Rendevous_Interruptus is

  task P is
     entry E;
     pragma Priority (0);
   end P;

   task Q is
      pragma Priority (0);
   end;

   task High_Priority is
      pragma Priority (15);
   end High_Priority;
   

   task body P is
      Y : Boolean := False;
   begin
      Main:
      loop
         accept E do          
            loop
               Y := not Y;
            end loop;
          end E;
      end loop Main;
   end P;

   task body Q is
   begin
      P.E;
   end;

   task High_Priority is
   begin
      loop
         delay 1.0;
         Text_IO.Put_Line ("Hello!");
      end loop;
   end High_Priority;

begin
   null;
end Rendevous_Interruptus;

Task High_Priority should wake up once a second, interrupt the rendevous
between P and Q, and print the message "Hello!".

>Thanks in advance, Nick.

Your welcome!  Keep the posts a-comin', and let us know how you're doin'!

matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271




  reply	other threads:[~1996-09-23  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-15  0:00 task question Nicolay Belofastow
1996-09-23  0:00 ` Matthew Heaney [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-12-10 22:12 Task question shaunpatterson
2007-12-10 22:29 ` gpriv
2007-12-10 22:51   ` shaunpatterson
2007-12-10 23:13     ` gpriv
2007-12-10 23:40 ` Robert A Duff
2007-12-11  0:43 ` anon
1997-10-16  0:00 Paul Van Gorp
1997-10-19  0:00 ` elaine.waybright
1997-11-01  0:00   ` Matthew Heaney
1997-10-21  0:00 ` Robert A Duff
1997-10-06  0:00 Larry Coon
1997-10-07  0:00 ` David C. Hoos, Sr.
1997-10-07  0:00   ` Larry Coon
1997-10-07  0:00   ` Steve O'Neill
1997-10-08  0:00   ` Matthew Heaney
1997-10-08  0:00   ` Tom Moran
1997-10-07  0:00 ` Matthew Heaney
1997-10-07  0:00   ` Larry Coon
1997-10-07  0:00 ` Robert A Duff
1997-10-13  0:00   ` Larry Coon
1997-10-30  0:00 ` Balmacara9
     [not found] <204266@QZCOM>
1986-09-26 17:28 ` Matts_Kallioniemi_QZ
replies disabled

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