comp.lang.ada
 help / color / mirror / Atom feed
From: loftus@wpllabs.UUCP (William Loftus)
Subject: Re: Immediate Reading in Tasks
Date: 19 Mar 91 03:19:46 GMT	[thread overview]
Message-ID: <loftus.5517@wpllabs.UUCP> (raw)
In-Reply-To: 739.27e1226c@vger.nsu.edu

In article <739.27e1226c@vger.nsu.edu> g_harrison@vger.nsu.edu (George C. Harrison, Norfolk State University) writes:
>Ada teachers and Real-Time types - 
>
>Do-While Jones in "Ada in Action" proposes a solution similar to the following:
>
>Define a function KEYPRESSED (boolean) and an IGET procedure that only works
>when KEYPRESSED is TRUE.  These subroutines call a task which essentially holds
>the incoming character as the value of a local [task] variable, setting
>KEYPRESSED to true until the character is retrieved from the task.
>
>So another task might do this:
>
>loop
>  do_stuff;
>  if keypressed then
>    iget(ch);
>    do_something_with_ch;
>  else
>    do_something_else;
>  end if;
>end loop;
>
>I welcome any and all ideas.  I have used the Do-While Jones method, but it
>seems to have a lot of overhead.  

It does have a lot of overhead.  In many real-time systems the cost of
executing "keypressed" is too much.  If the call to keypressed is 100ms and
you need to process a user typing (i.e.  ~50 wpm) and other information you
are devoting 1/2 sec/sec to processing keystrokes (these numbers come from
a project that I am currently working on).  Fortunately, keystrokes are
often interrupts, and many Ada systems allow the mapping of interrupts to
task entries.  Using this approach the task (see below for a quick example)
waits (allowing other tasks to execute) for a rendezvous from the system
software and is not constantly polling for keystroke availability.

task Keystroke is
   entry Key (Code : Byte);
end Keystroke;

task body Keystroke is
   Stroke : Byte;
begin
   loop
     accept Key (Code : Byte) do
        Stroke := Code;
     end accept;
     Rest_Of_System.Process_Keystroke (Stroke);
   end loop;
end Keystroke;

--
William Loftus                   (215) 668 3661
WPL Laboratories, Inc.           UUCP: loftus@wpllabs.UUCP
P.O. Box 111                     ARPA: loftus!wpllabs@prc.unisys.com
216 Wynne Lane
Penn Valley, PA 19072            Ada and Unix Software Consultants

  reply	other threads:[~1991-03-19  3:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-03-15 23:37 Immediate Reading in Tasks George C. Harrison, Norfolk State University
1991-03-19  3:19 ` William Loftus [this message]
1991-03-27 20:00 ` Use clauses in the visible parts of packages??? Scott Layson Burson
1991-03-28 17:17   ` Fred Stluka
replies disabled

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