From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA00529; Tue, 4 May 2004 09:47:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA01038 for ; Tue, 4 May 2004 09:47:20 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i447lJSH030285; Tue, 4 May 2004 09:47:19 +0200 Received: from bourg.inria.fr (bourg.inria.fr [128.93.11.100]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA01337; Tue, 4 May 2004 09:47:19 +0200 (MET DST) Received: from basile by bourg.inria.fr with local (Exim 4.32) id 1BKudd-0007mW-7P; Tue, 04 May 2004 09:46:49 +0200 Date: Tue, 4 May 2004 09:46:48 +0200 To: Ker Lutyn , caml-list@inria.fr Subject: Re: [Caml-list] file descriptor leaks? Message-ID: <20040504074648.GA29829@bourg.inria.fr> References: <20040503233232.83370.qmail@web40605.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20040503233232.83370.qmail@web40605.mail.yahoo.com> User-Agent: Mutt/1.5.6i From: Basile Starynkevitch local X-Miltered: at concorde with ID 40974A87.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 descriptor:01 basile:01 basile:01 2004:99 sock:01 descriptor:01 finalization:01 cristal:01 cristal:01 kernel:01 kernel:01 ocaml:01 0700,:01 unix:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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