From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f6ee8ca03c176d76 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-29 08:18:53 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uunet!sea.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: stupid question: how can I finish a program? Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Thu, 29 Aug 2002 15:18:05 GMT References: NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:28557 Date: 2002-08-29T15:18:05+00:00 List-Id: Dmitry A.Kazakov writes: > Robert A Duff wrote: > > > Dmitry A.Kazakov writes: > > > >> For example? Abort without any defined clean-up warranties absolutely > >> nothing. > >> > >> Otherwise, some sort of "finalization" should be defined. For instance: > >> known tasks killed, known memory returned. But (1) any sort of > >> finalization could still hang up. > > > > If you're running under a proper operating system, then all resources > > visible outside the program will be cleaned up when the program exits. > > Therefore, there is no need for finalization to clean up such resources. > > (I'm talking about the Ada finalization here.) > > But cleaning up the resources *is* a finalization. You can call it "finalization" if you like, but it's not Ada finalization. >... When a file is closed, > some code has to be executed [no matter on which context]. So there is no > difference in that respect between how Ada and how an OS does it. There is a huge difference: Ada finalization takes place inside the process, and a broken Ada program can cause finalization to not work. Cleanup performed by the OS happens in the OS, and cannot be damaged by anything the Ada program does, including using unchecked conversion of pointers to scribble all over the address space. Even a bug in the Ada compiler cannot damage the OS. As before, I'm only talking about a "proper" OS, which uses hardware memory protection to ensure security of OS data structures. (Of course if the OS has bugs, all bets are off.) The point is that you can count on the OS to (for example) close open file handles when the process exits. You cannot count on Ada finalization to do that. >...The > actual difference is that Ada precisely specifies what "task abort" means. > > > Certainly, "exit" will > > kill all tasks in the program and recover all memory. There is no need > > for finalization to clean up resources internal to the program, either > > -- the program is about to vanish. > > No OS can warranty that *all* external resources will be freed. Well, OK, I admit I overstated my case. Nonetheless, if you know what external resources your program uses, and you are running under a proper OS, then you can deal with these issues. > That's clear, but what kind of external finalization has to be performed? > Because you cannot warranty that *all* external resources will be freed, > you should specify which ones will be. It's not the job of the Ada RM to talk about what happens outside the Ada program. >... It is possible, but IMO very > difficult. Alternatively, you can say that it warranties nothing. Then > well, the external *portable* effect = "does nothing". Who might need that > thing? The Ada RM warrants nothing, but that's OK -- look it up in your OS manual. None of this has anything to do with calling "exit" prematurely. All these horrible things and lack of warranties you mention are true when an Ada program exits normally (by getting to the end of the program in the usual way). If you run this simple program: procedure Main is begin null; end Main; there is no guarantee in the Ada RM that the OS won't leak memory, or forget to close the stdout file handle, etc. Creating a new feature like "exit()" would not make things any worse. It's not Ada's job to talk about what the OS ought to do. - Bob