From: Jerry <lanceboyle@qwest.net>
Subject: Re: How to exit a loop with keyboard input
Date: Tue, 13 Apr 2010 12:38:23 -0700 (PDT)
Date: 2010-04-13T12:38:23-07:00 [thread overview]
Message-ID: <52ffa6a4-8b2d-4643-b7d3-154e553f1c35@j21g2000yqh.googlegroups.com> (raw)
In-Reply-To: 9667c83e-23d7-4c77-8dd9-d279c54b1c08@y14g2000yqm.googlegroups.com
On Apr 12, 6:59 am, John McCormick <mccorm...@cs.uni.edu> wrote:
> On Apr 12, 5:36 am, Jerry <lancebo...@qwest.net> wrote:
>
> > Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:
>
> > MBPro:/ me$ gnat
> > GNAT 4.4.0 20080314 (experimental) [trunk revision 133226]
> > Copyright 1996-2007, Free Software Foundation, Inc.
>
> > I've tried the program on three different terminal programs with the
> > same result: it prints out 0 and waits for RETURN, then prints out 1,
> > etc. If I hit q then RETURN the loop is exited. But the loop never
> > "free-runs."
>
> > Jerry
>
> Perhaps the Asynchronous Transfer of Control mechanism would be
> appropriate. Here is some GNAT code that runs under Windows XP in
> which the input loop is interrutpted by Ctrl-c. The interrupt handler
> must be at the library level so I put it in its own package.
>
> select
> Ctrl_C_Interrupt.Wait;
> Put_Line ("Handled Ctrl C");
> then abort
> loop
> Put_Line ("Enter an integer (Ctrl C to exit)");
> Get (Value);
> Put (Value);
> New_Line;
> end loop;
> end select;
>
> -----------------------------------------------------------
> with Ada.Interrupts.Names;
> package Ctrl_C is
>
> protected Ctrl_C_Interrupt is
> entry Wait;
> procedure Handler;
> pragma Attach_Handler (Handler, Ada.Interrupts.Names.SIGINT);
> pragma Interrupt_Priority;
> private
> Received : Boolean := False;
> end Ctrl_C_Interrupt;
> end Ctrl_C;
>
> -----------------------------------------------------------
> package body Ctrl_C is
>
> protected body Ctrl_C_Interrupt is
> procedure Handler is
> begin
> Received := True;
> end Handler;
>
> entry Wait when Received is
> begin
> Received := False;
> end Wait;
> end Ctrl_C_Interrupt;
>
> end Ctrl_C;
>
> John
Thanks, John.
Your solution does work (after I added pragma
Unreserve_All_Interrupts;) and I think I can adapt it to my specific
problem but it takes 100% of CPU time so I'm not sure how that would
affect my number-crunching loop. (A similar solution was suggested by
Chris on the GNAT-OSX list but I haven't tried it yet.)
Jerry
next prev parent reply other threads:[~2010-04-13 19:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-12 4:12 How to exit a loop with keyboard input Jerry
2010-04-12 8:50 ` Georg Bauhaus
2010-04-12 9:21 ` Manuel Collado
2010-04-12 10:36 ` Jerry
2010-04-12 13:59 ` John McCormick
2010-04-13 19:38 ` Jerry [this message]
2010-04-12 15:14 ` Tero Koskinen
2010-04-12 16:16 ` John B. Matthews
2010-04-12 20:04 ` Simon Wright
2010-04-13 19:51 ` Jerry
2010-04-13 21:22 ` Simon Wright
2010-04-15 3:39 ` Jerry
2010-04-15 4:08 ` John B. Matthews
2010-04-15 18:51 ` Jerry
2010-04-16 0:44 ` John B. Matthews
2010-04-16 4:43 ` Simon Wright
2010-04-16 14:03 ` John B. Matthews
2010-04-15 19:22 ` Simon Wright
2010-04-16 10:25 ` Jerry
2010-04-12 20:57 ` Alex Mentis
2010-04-12 22:51 ` Jerry
2010-04-16 0:06 ` BrianG
2010-04-16 7:23 ` Jerry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox