caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] at_exit functions not called during exit
@ 2002-02-18 13:07 Hendrik Tews
  2002-02-18 13:21 ` Warp
  2002-02-18 16:33 ` Xavier Leroy
  0 siblings, 2 replies; 4+ messages in thread
From: Hendrik Tews @ 2002-02-18 13:07 UTC (permalink / raw)
  To: caml-list

Hi,

I noticed that functions registered with Pervasives.at_exit are
not called when a C-library function calls exit. Is this a bug or
a feature?

Assuming it is a feature I experimented with atexit and callbacks
to ocaml. Now I have the following question:

When a ocaml program is going down, is there a point of time
after which I should not callback from C to Ocaml (because
libraries/the garbage collector are deinitialised)?

If yes, how can I check for this condition?

Bye,

Hendrik
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] at_exit functions not called during exit
  2002-02-18 13:07 [Caml-list] at_exit functions not called during exit Hendrik Tews
@ 2002-02-18 13:21 ` Warp
  2002-02-18 16:21   ` Hendrik Tews
  2002-02-18 16:33 ` Xavier Leroy
  1 sibling, 1 reply; 4+ messages in thread
From: Warp @ 2002-02-18 13:21 UTC (permalink / raw)
  To: Hendrik Tews, caml-list

> I noticed that functions registered with Pervasives.at_exit are
> not called when a C-library function calls exit. Is this a bug or
> a feature?

If you call the exit() C function in your C-library, it'll exit regardless
you're using OCaml or any other feature.
BTW, Pervasives.at_exit seems to be only called when an unhandled exception
reach the top-level.

Warp

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] at_exit functions not called during exit
  2002-02-18 13:21 ` Warp
@ 2002-02-18 16:21   ` Hendrik Tews
  0 siblings, 0 replies; 4+ messages in thread
From: Hendrik Tews @ 2002-02-18 16:21 UTC (permalink / raw)
  To: Warp; +Cc: caml-list

Hi,

Warp writes:
   From: "Warp" <warplayer@free.fr>
   Date: Mon, 18 Feb 2002 14:21:47 +0100
   Subject: Re: [Caml-list] at_exit functions not called during exit
   
   [my statment deleted]
   
   If you call the exit() C function in your C-library, it'll exit regardless
   you're using OCaml or any other feature.

No, it calls functions registered via atexit or on_exit, which
can do arbitrary things (including longjumping and continuing).

   BTW, Pervasives.at_exit seems to be only called when an unhandled exception
   reach the top-level.
   
Functions registered via at_exit are at least called during
normal termination. And the manual says

     They will not be called if
     the program terminates because of an uncaught exception.

which is not true in ocaml-3.04.

Bye,

Hendrik
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] at_exit functions not called during exit
  2002-02-18 13:07 [Caml-list] at_exit functions not called during exit Hendrik Tews
  2002-02-18 13:21 ` Warp
@ 2002-02-18 16:33 ` Xavier Leroy
  1 sibling, 0 replies; 4+ messages in thread
From: Xavier Leroy @ 2002-02-18 16:33 UTC (permalink / raw)
  To: Hendrik Tews; +Cc: caml-list

> I noticed that functions registered with Pervasives.at_exit are
> not called when a C-library function calls exit. Is this a bug or
> a feature?

I'd say a feature.  Caml's at_exit functions are called when the
process stops because Caml asked it to, e.g. via Pervasives.exit
or an uncaught exception.  It wasn't clear to me whether you'd want to
do this as well if the C code decides to stop the process.

> Assuming it is a feature I experimented with atexit and callbacks
> to ocaml.

Yes, that's the way I'd recommend to get Caml finalization when C exits.

> Now I have the following question:
> When a ocaml program is going down, is there a point of time
> after which I should not callback from C to Ocaml (because
> libraries/the garbage collector are deinitialised)?

The OCaml runtime system, once initialized, is never de-initialized,
so I'd say you can call back from C to OCaml at any time after
initialization.

> Functions registered via at_exit are at least called during
> normal termination. And the manual says
>    They will not be called if
>    the program terminates because of an uncaught exception.
> which is not true in ocaml-3.04.

Well spotted.  Will fix the docs.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-02-18 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-18 13:07 [Caml-list] at_exit functions not called during exit Hendrik Tews
2002-02-18 13:21 ` Warp
2002-02-18 16:21   ` Hendrik Tews
2002-02-18 16:33 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).