comp.lang.ada
 help / color / mirror / Atom feed
* Terminate program in Ada95
@ 2000-11-27  0:00 Atle R�stad
  2000-11-27  0:00 ` Marc A. Criley
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Atle R�stad @ 2000-11-27  0:00 UTC (permalink / raw)


Hi

How can I do an unconditionaly terminate of my program in Ada95?

Why I want to do it? I have a program were some of the tasks are listning to
messages received/or sending on a socket. I want to write a testprogram, and
reuse the tasks that takes care of the sending/receiving of messages. But
when my testprogram should end it will still have some tasks open for
sending/receiving messages and it keeps waitng for those tasks to end (which
they will not do). Since I'm not allowed to modify the tasks I'm reusing I
want an command that terminates the whole program. (Like java.system.exit()
in java).

Regards Atle






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

* Re: Terminate program in Ada95
  2000-11-27  0:00 Terminate program in Ada95 Atle R�stad
@ 2000-11-27  0:00 ` Marc A. Criley
  2000-11-27  0:00 ` Alfred Hilscher
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marc A. Criley @ 2000-11-27  0:00 UTC (permalink / raw)


"Atle R�stad" wrote:
> 
> Hi
> 
> How can I do an unconditionaly terminate of my program in Ada95?

If you're using a Unix variant, you can interface to the "exit" function
and invoke that.  Or if you're using GNAT, you can call
GNAT.OS_Lib.OS_Exit.

Another approach is to abort the tasks (see RM 9.8) that can't be
terminated.

> 
> Why I want to do it? I have a program were some of the tasks are listning to
> messages received/or sending on a socket. I want to write a testprogram, and
> reuse the tasks that takes care of the sending/receiving of messages. But
> when my testprogram should end it will still have some tasks open for
> sending/receiving messages and it keeps waitng for those tasks to end (which
> they will not do). Since I'm not allowed to modify the tasks I'm reusing I
> want an command that terminates the whole program. (Like java.system.exit()
> in java).

That situation is somewhat odd. Code was written to monitor sockets, but
there was no provision made for terminating the monitoring??

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation




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

* Re: Terminate program in Ada95
  2000-11-27  0:00 Terminate program in Ada95 Atle R�stad
                   ` (3 preceding siblings ...)
  2000-11-27  0:00 ` Robert A Duff
@ 2000-11-27  0:00 ` Ted Dennison
  4 siblings, 0 replies; 8+ messages in thread
From: Ted Dennison @ 2000-11-27  0:00 UTC (permalink / raw)


Atle R�stad wrote:

> they will not do). Since I'm not allowed to modify the tasks I'm reusing I
> want an command that terminates the whole program. (Like java.system.exit()
> in java).

The way I see it, your choices are:

    * Issue a "terminate" command for those wayward tasks. This requires 
      visibility to the task declarations, which means that if the task 
      is declared only within a package body somewhere, you will need to 
      write some kind of "kill" procedure in that package.
    * See if your OS has some kind of  "Exit" system call, and use that. 
      That is *exactly* what you are doing in Java when you do a 
      "java.system.exit()".
      
-- 
T.E.D.

Home - mailto:dennison@telepath.com  Work - mailto:dennison@ssd.fsi.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html  ICQ  - 10545591





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

* Re: Terminate program in Ada95
  2000-11-27  0:00 Terminate program in Ada95 Atle R�stad
  2000-11-27  0:00 ` Marc A. Criley
  2000-11-27  0:00 ` Alfred Hilscher
@ 2000-11-27  0:00 ` Mats Weber
  2000-11-27  0:00   ` Florian Weimer
  2000-11-27  0:00 ` Robert A Duff
  2000-11-27  0:00 ` Ted Dennison
  4 siblings, 1 reply; 8+ messages in thread
From: Mats Weber @ 2000-11-27  0:00 UTC (permalink / raw)


If it is UNIX or UNIX-like (which it probably is if you are using
sockets) then you can close the sockets with pending I/O operations from
outside the task doing the socket I/O. This will make any pending
opertion on the socket exit with an error code that is hopefully handled
in the task.

My advice: get the termination problems right as soon as possible. Doing
it afterwards, when the complexity of your application will have
increased, will be very difficult.




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

* Re: Terminate program in Ada95
  2000-11-27  0:00 Terminate program in Ada95 Atle R�stad
                   ` (2 preceding siblings ...)
  2000-11-27  0:00 ` Mats Weber
@ 2000-11-27  0:00 ` Robert A Duff
  2000-11-27  0:00 ` Ted Dennison
  4 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 2000-11-27  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

"Atle R�stad" <aer@edh.ericsson.se> writes:

> How can I do an unconditionaly terminate of my program in Ada95?

You might want to use terminate alternatives in your tasks.
Or, you can call the operating system "exit" routine -- use pragma Import.
Or, you can abort them.
Or, you can abort the environment task, which will cause all subtasks to
also be aborted, thus killing the whole program.

To get your hands on the environment task, call Current_Task from the
env task -- that is, put something like this in a library package:

    Environment_Task: constant Task_ID := Current_Task;

You can then use Abort_Task on that.

Abortion will cause finalization actions to happen.
Calling "exit" probably will not; that's outside the language.

- Bob




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

* Re: Terminate program in Ada95
  2000-11-27  0:00 Terminate program in Ada95 Atle R�stad
  2000-11-27  0:00 ` Marc A. Criley
@ 2000-11-27  0:00 ` Alfred Hilscher
  2000-11-27  0:00   ` Warren W. Gay VE3WWG
  2000-11-27  0:00 ` Mats Weber
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Alfred Hilscher @ 2000-11-27  0:00 UTC (permalink / raw)


Hi,

some time ago I had the same problem (on WinNT). 
I did two things: 
 a) I close the socket from an other task (that works for TCP sockets
but not for UDP in my environment)
 b) In that cases where a) does not work, I send explizitly data to that
socket (so the task returns from the receive call and continues) and
call "abort".

Regards,
Alfred

"Atle R�stad" wrote:
> 
> Hi
> 
> How can I do an unconditionaly terminate of my program in Ada95?
> 
> Why I want to do it? I have a program were some of the tasks are listning to
> messages received/or sending on a socket. I want to write a testprogram, and
> reuse the tasks that takes care of the sending/receiving of messages. But
> when my testprogram should end it will still have some tasks open for
> sending/receiving messages and it keeps waitng for those tasks to end (which
> they will not do). Since I'm not allowed to modify the tasks I'm reusing I
> want an command that terminates the whole program. (Like java.system.exit()
> in java).
> 
> Regards Atle




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

* Re: Terminate program in Ada95
  2000-11-27  0:00 ` Alfred Hilscher
@ 2000-11-27  0:00   ` Warren W. Gay VE3WWG
  0 siblings, 0 replies; 8+ messages in thread
From: Warren W. Gay VE3WWG @ 2000-11-27  0:00 UTC (permalink / raw)


Alfred Hilscher wrote:

> Hi,
>
> some time ago I had the same problem (on WinNT).
> ...snip...
>  b) In that cases where a) does not work, I send explizitly data to that
> socket (so the task returns from the receive call and continues) and
> call "abort".

This however, leaves your network service open to "denial of service"
attacks.

--
Warren W. Gay VE3WWG
http://members.home.net/ve3wwg






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

* Re: Terminate program in Ada95
  2000-11-27  0:00 ` Mats Weber
@ 2000-11-27  0:00   ` Florian Weimer
  0 siblings, 0 replies; 8+ messages in thread
From: Florian Weimer @ 2000-11-27  0:00 UTC (permalink / raw)


Mats Weber <matsw@mail.com> writes:

> If it is UNIX or UNIX-like (which it probably is if you are using
> sockets) then you can close the sockets with pending I/O operations from
> outside the task doing the socket I/O. This will make any pending
> opertion on the socket exit with an error code that is hopefully handled
> in the task.

This might introduce a race condition because the file descriptor
used by the socket might be reused soon.  I think the shutdown socket
operation is better than simply closing the socket under these
circumstances (it will cause subsequent operations on the socket to
fail, but doesn't release the file descriptor at once).




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

end of thread, other threads:[~2000-11-27  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-27  0:00 Terminate program in Ada95 Atle R�stad
2000-11-27  0:00 ` Marc A. Criley
2000-11-27  0:00 ` Alfred Hilscher
2000-11-27  0:00   ` Warren W. Gay VE3WWG
2000-11-27  0:00 ` Mats Weber
2000-11-27  0:00   ` Florian Weimer
2000-11-27  0:00 ` Robert A Duff
2000-11-27  0:00 ` Ted Dennison

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