comp.lang.ada
 help / color / mirror / Atom feed
* problem with ada.interrupts
@ 2005-08-10 16:01 evangeli
  2005-08-10 18:00 ` Robert A Duff
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: evangeli @ 2005-08-10 16:01 UTC (permalink / raw)


hello
in my program i want to catch the interruption by the user, e.g.,
ctrl+c.
i looked at the RM and it seems that package ada.interrupts is designed
to do this kind of things.
so i tested this little program (my compiler is gnat 3.15p) :


with
  Ada.Interrupts,
  Ada.Interrupts.Names,
  Ada.Text_Io;

procedure Test is

   protected Interruption_Handler is
      procedure SIGINT_Handler;
   end Interruption_Handler;
   protected body Interruption_Handler is
      procedure SIGINT_Handler is
      begin
         Ada.Text_Io.Put_Line("interruption");
      end;
   end Interruption_Handler;

begin

Ada.Interrupts.Attach_Handler(Interruption_Handler.SIGINT_Handler'Access,
                                 Ada.Interrupts.Names.SIGINT);
   Ada.Text_Io.Put_Line("ok");
   delay 5.0;
end;


this compiles fine, but when i launch it, nothing happens (not even the
put_line("ok")).
it seems that even this little program does not terminate :

with
  Ada.Interrupts;

procedure Test is
begin
   null:
end;

i suspect a problem in the elaboration of package Ada.Interrupts, but i
have no idea of how to deal with it.
any idea?

Thanks for any help

Sami




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

* Re: problem with ada.interrupts
  2005-08-10 16:01 problem with ada.interrupts evangeli
@ 2005-08-10 18:00 ` Robert A Duff
  2005-08-10 18:19 ` jimmaureenrogers
  2005-08-25 12:25 ` Thierry Pirot
  2 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 2005-08-10 18:00 UTC (permalink / raw)


evangeli@cnam.fr writes:

> hello
> in my program i want to catch the interruption by the user, e.g.,
> ctrl+c.
> i looked at the RM and it seems that package ada.interrupts is designed
> to do this kind of things.

Yes.  I have done this successfully, on both GNAT and Sofcheck's
AdaMagic compilers, on WindowsXP, Linux, and Solaris.

Technically, it is wrong to do I/O in a protected procedure, but some
compilers allow it.  You should instead have the handler procedure
trigger an entry barrier, and have some task wait for the entry.

You need a pragma on the SIGINT_Handler.  Pragma Attach_Handler is
simpler; Interrupt_Handler is more powerful.  See the RM for details.

On GNAT, you need pragma Unreserve_All_Interrupts on some systems.
See the GNAT docs.

> it seems that even this little program does not terminate :
> 
> with
>   Ada.Interrupts;
> 
> procedure Test is
> begin
>    null:
> end;
> 
> i suspect a problem in the elaboration of package Ada.Interrupts, but i
> have no idea of how to deal with it.
> any idea?

No.  You could try stepping through that code in gdb.

- Bob



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

* Re: problem with ada.interrupts
  2005-08-10 16:01 problem with ada.interrupts evangeli
  2005-08-10 18:00 ` Robert A Duff
@ 2005-08-10 18:19 ` jimmaureenrogers
  2005-08-25 12:25 ` Thierry Pirot
  2 siblings, 0 replies; 4+ messages in thread
From: jimmaureenrogers @ 2005-08-10 18:19 UTC (permalink / raw)


evangeli@cnam.fr wrote:
> hello
> in my program i want to catch the interruption by the user, e.g.,
> ctrl+c.
> i looked at the RM and it seems that package ada.interrupts is designed
> to do this kind of things.
> so i tested this little program (my compiler is gnat 3.15p) :
>

Consider the following statements from the Ada Reference Manual:

The form of a pragma Interrupt_Handler is as follows:

   pragma Interrupt_Handler(handler_name);

   The form of a pragma Attach_Handler is as follows:

   pragma Attach_Handler(handler_name, expression);

Name Resolution Rules

For the Interrupt_Handler and Attach_Handler pragmas, the handler_name
shall resolve to denote a protected procedure with a parameterless
profile.

For the Attach_Handler pragma, the expected type for the expression is
Interrupts.Interrupt_ID (see C.3.2).

Legality Rules

The Attach_Handler pragma is only allowed immediately within the
protected_definition where the corresponding subprogram is declared.
The corresponding protected_type_declaration or
single_protected_declaration shall be a library level declaration.

The Interrupt_Handler pragma is only allowed immediately within a
protected_definition. The corresponding protected_type_declaration
shall be a library level declaration. In addition, any
object_declaration of such a  type shall be a library level
declaration.

       -------

Your Attach_Handler pragma is misplaced.
You do not have an Interrupt_Handler pragma.

Your protected object is not defined at a library level.

Jim Rogers




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

* Re: problem with ada.interrupts
  2005-08-10 16:01 problem with ada.interrupts evangeli
  2005-08-10 18:00 ` Robert A Duff
  2005-08-10 18:19 ` jimmaureenrogers
@ 2005-08-25 12:25 ` Thierry Pirot
  2 siblings, 0 replies; 4+ messages in thread
From: Thierry Pirot @ 2005-08-25 12:25 UTC (permalink / raw)


> with
>   Ada.Interrupts,
>   Ada.Interrupts.Names,
>   Ada.Text_Io;
> 
> procedure Test is
> 
>    protected Interruption_Handler is
>       procedure SIGINT_Handler;
>    end Interruption_Handler;
>    protected body Interruption_Handler is
>       procedure SIGINT_Handler is
>       begin
>          Ada.Text_Io.Put_Line("interruption");
>       end;
>    end Interruption_Handler;
> 
> begin
> 
> Ada.Interrupts.Attach_Handler(Interruption_Handler.SIGINT_Handler'Access,
>                                  Ada.Interrupts.Names.SIGINT);
>    Ada.Text_Io.Put_Line("ok");
>    delay 5.0;
> end;
> 
> 
> this compiles fine, but when i launch it, nothing happens (not even the
> put_line("ok")).
> it seems that even this little program does not terminate :
> 
> with
>   Ada.Interrupts;
> 
> procedure Test is
> begin
>    null:
> end;

(My two cents) 
How did you launch it ?  Maybe you forgot "test" is an internal shell command. 
What about 
./test
which test
help test
-- 
   Take it Easy          Don't worry            Be Happy

                           Thierry

�������o�o��������o�o��������o�o��������o�o��������o�o�������



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

end of thread, other threads:[~2005-08-25 12:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-10 16:01 problem with ada.interrupts evangeli
2005-08-10 18:00 ` Robert A Duff
2005-08-10 18:19 ` jimmaureenrogers
2005-08-25 12:25 ` Thierry Pirot

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