caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile Starynkevitch local <basile.starynkevitch@inria.fr>
To: Ker Lutyn <ker527mail@yahoo.com>, caml-list@inria.fr
Subject: Re: [Caml-list] file descriptor leaks?
Date: Tue, 4 May 2004 09:46:48 +0200	[thread overview]
Message-ID: <20040504074648.GA29829@bourg.inria.fr> (raw)
In-Reply-To: <20040503233232.83370.qmail@web40605.mail.yahoo.com>

On Mon, May 03, 2004 at 04:32:32PM -0700, Ker Lutyn wrote:
[...]

> Assuming f does not close the fd when it's done, [...] is this
> better?
> 
> while true do
>   let fd, _ = Unix.accept sock in
>   let g fd = try f fd; Unix.close fd with e -> Unix.close fd; raise e in
>   ignore (Thread.create g fd)
> done
> 

Yes. First, a file descriptor is mostly heavy in the OS kernel side;
inside a process, an fd is just an integer. To free the fd (kernel)
resource, you *have* to call Unix.close (i.e. to call the close(2)
system call).

Second, there are no implicit call to the close(2) system call inside
the Ocaml system (there used to be, long time ago, implicit close of
channels by the GC. This finalization is gone).

So yes, every file descriptor you got thru accept has to be explicitly
closed. Some higher level functions in the Unix library happen to do
so.

-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
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


  reply	other threads:[~2004-05-04  7:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-03 23:32 Ker Lutyn
2004-05-04  7:46 ` Basile Starynkevitch local [this message]
2004-05-04  9:15   ` Henri DF
2004-05-04  9:31     ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040504074648.GA29829@bourg.inria.fr \
    --to=basile.starynkevitch@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=ker527mail@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).