comp.lang.ada
 help / color / mirror / Atom feed
* How do I end the program?
@ 2002-02-04 23:15 David Starner
  2002-02-05  3:52 ` dale
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: David Starner @ 2002-02-04 23:15 UTC (permalink / raw)


How do I exit the program? It may seem like a silly question, but I'm
trying to exit from a function called from a callback written in C, so I
can't just return or raise an exception. glutMainLoop never returns, so
I can't run off the end of the main function. I used
GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?

-- 
David Starner - starner@okstate.edu, dvdeug/jabber.com (Jabber)
Pointless website: http://dvdeug.dhis.org
What we've got is a blue-light special on truth. It's the hottest thing 
with the youth. -- Information Society, "Peace and Love, Inc."



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

* Re: How do I end the program?
  2002-02-04 23:15 How do I end the program? David Starner
@ 2002-02-05  3:52 ` dale
  2002-02-05  6:17   ` Simon Wright
  2002-02-05  7:39   ` Dmitriy Anisimkov
  2002-02-05 12:35 ` David C. Hoos
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: dale @ 2002-02-05  3:52 UTC (permalink / raw)


starner@okstate.edu wrote:

> How do I exit the program? It may seem like a silly question, but I'm
> trying to exit from a function called from a callback written in C, so I
> can't just return or raise an exception. glutMainLoop never returns, so
> I can't run off the end of the main function. I used
> GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?


No not really. One way of doing it is to define an exception...

   Quit_Program : Exception;


then have a handler at the main program level....

   exception 
      when Quit_Program => null;
   end;


Before you do that you can call Ada.Command_Line.Set_Exit_Status.


Dale



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

* Re: How do I end the program?
  2002-02-05  3:52 ` dale
@ 2002-02-05  6:17   ` Simon Wright
  2002-02-05  7:39   ` Dmitriy Anisimkov
  1 sibling, 0 replies; 10+ messages in thread
From: Simon Wright @ 2002-02-05  6:17 UTC (permalink / raw)


dale <dale@cs.rmit.edu.au> writes:

> starner@okstate.edu wrote:
> 
> > How do I exit the program? It may seem like a silly question, but I'm
> > trying to exit from a function called from a callback written in C, so I
> > can't just return or raise an exception. glutMainLoop never returns, so
> > I can't run off the end of the main function. I used
> > GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?
> 
> 
> No not really. One way of doing it is to define an exception...

There has been at least one thread on this on cla; it's particularly
interesting when you have tasks you don't know about. The general idea
is to abort the environment task.



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

* Re: How do I end the program?
  2002-02-05  3:52 ` dale
  2002-02-05  6:17   ` Simon Wright
@ 2002-02-05  7:39   ` Dmitriy Anisimkov
  1 sibling, 0 replies; 10+ messages in thread
From: Dmitriy Anisimkov @ 2002-02-05  7:39 UTC (permalink / raw)


> > GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?
>
> No not really. One way of doing it is to define an exception...
>
>    Quit_Program : Exception;
>
> then have a handler at the main program level....
>
>    exception
>       when Quit_Program => null;
>    end;
>
> Before you do that you can call Ada.Command_Line.Set_Exit_Status.

You could not terminate programm this way from task.
But the GNAT.OS_Lib.OS_Exit could.





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

* Re: How do I end the program?
  2002-02-04 23:15 How do I end the program? David Starner
  2002-02-05  3:52 ` dale
@ 2002-02-05 12:35 ` David C. Hoos
  2002-02-05 13:26 ` Stephen Leake
  2002-02-06  3:16 ` Steve Doiel
  3 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos @ 2002-02-05 12:35 UTC (permalink / raw)


If you don't want to use a compiler-specific solution,
you can always do a Pragma Import of the exit function from the
C library.

----- Original Message ----- 
From: "David Starner" <dvdeug@x8b4e53cd.dhcp.okstate.edu>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Monday, February 04, 2002 5:15 PM
Subject: How do I end the program?


> How do I exit the program? It may seem like a silly question, but I'm
> trying to exit from a function called from a callback written in C, so I
> can't just return or raise an exception. glutMainLoop never returns, so
> I can't run off the end of the main function. I used
> GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?
> 
> -- 
> David Starner - starner@okstate.edu, dvdeug/jabber.com (Jabber)
> Pointless website: http://dvdeug.dhis.org
> What we've got is a blue-light special on truth. It's the hottest thing 
> with the youth. -- Information Society, "Peace and Love, Inc."
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 




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

* Re: How do I end the program?
  2002-02-04 23:15 How do I end the program? David Starner
  2002-02-05  3:52 ` dale
  2002-02-05 12:35 ` David C. Hoos
@ 2002-02-05 13:26 ` Stephen Leake
  2002-02-06  3:16 ` Steve Doiel
  3 siblings, 0 replies; 10+ messages in thread
From: Stephen Leake @ 2002-02-05 13:26 UTC (permalink / raw)


David Starner <dvdeug@x8b4e53cd.dhcp.okstate.edu> writes:

> How do I exit the program? It may seem like a silly question, but I'm
> trying to exit from a function called from a callback written in C, so I
> can't just return or raise an exception. glutMainLoop never returns, so
> I can't run off the end of the main function. I used
> GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?

To exit cleanly, you need to tell the top level application to exit.
There should be a return value, or out parameter, or global variable
that says "give up and exit, please".

-- 
-- Stephe



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

* Re: How do I end the program?
  2002-02-04 23:15 How do I end the program? David Starner
                   ` (2 preceding siblings ...)
  2002-02-05 13:26 ` Stephen Leake
@ 2002-02-06  3:16 ` Steve Doiel
  2002-02-06  7:46   ` Dale Stanbrough
  3 siblings, 1 reply; 10+ messages in thread
From: Steve Doiel @ 2002-02-06  3:16 UTC (permalink / raw)


Yes, but it isn't pretty.

Take a look at the module: Ada.Task_Identification.

In the main procedure of your program, before entering glutMainLoop save off
the task ID of the environment task.

  env_task_id := Ada.Task_Identification.Current_Task;

When you want to kill the program call:

  Ada.Task_Identification.Abort_Task( env_task_id );

When you kill the environment task, all subordinate tasks are terminated as
well.

With GNAT 3.14p, I get the message:
  Execution terminated by abort of environment task

On the console window of my test program.

SteveD

"David Starner" <dvdeug@x8b4e53cd.dhcp.okstate.edu> wrote in message
news:a3n4mj$9qe1@news.cis.okstate.edu...
> How do I exit the program? It may seem like a silly question, but I'm
> trying to exit from a function called from a callback written in C, so I
> can't just return or raise an exception. glutMainLoop never returns, so
> I can't run off the end of the main function. I used
> GNAT.OS_Lib.OS_Exit. Is there a pure Ada alternative?
>
> --
> David Starner - starner@okstate.edu, dvdeug/jabber.com (Jabber)
> Pointless website: http://dvdeug.dhis.org
> What we've got is a blue-light special on truth. It's the hottest thing
> with the youth. -- Information Society, "Peace and Love, Inc."





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

* Re: How do I end the program?
  2002-02-06  3:16 ` Steve Doiel
@ 2002-02-06  7:46   ` Dale Stanbrough
  2002-02-06  8:40     ` Martin Dowie
  2002-02-06 17:55     ` Robert A Duff
  0 siblings, 2 replies; 10+ messages in thread
From: Dale Stanbrough @ 2002-02-06  7:46 UTC (permalink / raw)


Steve Doiel wrote:

> In the main procedure of your program, before entering glutMainLoop save off
> the task ID of the environment task.
> 
>   env_task_id := Ada.Task_Identification.Current_Task;
> 
> When you want to kill the program call:
> 
>   Ada.Task_Identification.Abort_Task( env_task_id );
> 
> When you kill the environment task, all subordinate tasks are terminated as
> well.
> 
> With GNAT 3.14p, I get the message:
>   Execution terminated by abort of environment task
> 
> On the console window of my test program.

Well, i'm not sure that would work. What if one of the tasks is 
a library level task, i.e. declared and elaborated in a library
level package? I'm not sure that there is a "parent" task in that
case.


Dale



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

* Re: How do I end the program?
  2002-02-06  7:46   ` Dale Stanbrough
@ 2002-02-06  8:40     ` Martin Dowie
  2002-02-06 17:55     ` Robert A Duff
  1 sibling, 0 replies; 10+ messages in thread
From: Martin Dowie @ 2002-02-06  8:40 UTC (permalink / raw)


> > In the main procedure of your program, before entering glutMainLoop save
off
> > the task ID of the environment task.
> >
> >   env_task_id := Ada.Task_Identification.Current_Task;
> >
> > When you want to kill the program call:
> >
> >   Ada.Task_Identification.Abort_Task( env_task_id );
> >
> > When you kill the environment task, all subordinate tasks are terminated
as
> > well.
> >
> > With GNAT 3.14p, I get the message:
> >   Execution terminated by abort of environment task
> >
> > On the console window of my test program.
>
> Well, i'm not sure that would work. What if one of the tasks is
> a library level task, i.e. declared and elaborated in a library
> level package? I'm not sure that there is a "parent" task in that
> case.

This was covered circa nov/dec 2000 and the above solution was
proposed with the slight twist of "env_task_id" being a package
level variable assigned during elaboration. The rationale then
was that all elaboration occurs within the scope of the environment
task.

Can't remember who put forward the example - I have a feeling they
had a french sounding name though! :-)





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

* Re: How do I end the program?
  2002-02-06  7:46   ` Dale Stanbrough
  2002-02-06  8:40     ` Martin Dowie
@ 2002-02-06 17:55     ` Robert A Duff
  1 sibling, 0 replies; 10+ messages in thread
From: Robert A Duff @ 2002-02-06 17:55 UTC (permalink / raw)


Dale Stanbrough <dstanbro@bigpond.net.au> writes:

> Well, i'm not sure that would work. What if one of the tasks is 
> a library level task, i.e. declared and elaborated in a library
> level package? I'm not sure that there is a "parent" task in that
> case.

There was some confusion about this in Ada 83, but in Ada 95,
the library-package tasks depend on the environment task,
so aborting the env task aborts all other tasks, too.
(I believe that was the original intent of Ada 83, too,
but there was some confusing wording in the RM.)

- Bob



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

end of thread, other threads:[~2002-02-06 17:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-04 23:15 How do I end the program? David Starner
2002-02-05  3:52 ` dale
2002-02-05  6:17   ` Simon Wright
2002-02-05  7:39   ` Dmitriy Anisimkov
2002-02-05 12:35 ` David C. Hoos
2002-02-05 13:26 ` Stephen Leake
2002-02-06  3:16 ` Steve Doiel
2002-02-06  7:46   ` Dale Stanbrough
2002-02-06  8:40     ` Martin Dowie
2002-02-06 17:55     ` Robert A Duff

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