caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Rich Neswold <rich.neswold@gmail.com>
Cc: Goswin von Brederlow <goswin-v-b@web.de>, caml-list@inria.fr
Subject: Re: [Caml-list] Preventing values from escaping a context
Date: Wed, 10 Feb 2010 22:37:53 +0100	[thread overview]
Message-ID: <87hbposrf2.fsf@frosties.localdomain> (raw)
In-Reply-To: <14cf844b1002101000p2737c63yd311be691c9661b1@mail.gmail.com> (Rich Neswold's message of "Wed, 10 Feb 2010 12:00:30 -0600")

Rich Neswold <rich.neswold@gmail.com> writes:

> On Wed, Feb 10, 2010 at 2:55 AM, Goswin von Brederlow <goswin-v-b@web.de>
> wrote:
>
>     Why not make the context a custom block with finalizer? The finalizer
>     then frees the resources. If the context escapes then it remains alive
>     and the finalizer will not be called any time soon. Only when it is no
>     longer reachable. That would also allow someone to create a context
>     and use it for a number of operations before forgeting it.
>
>
> Good point. I'll need to consider this as a possible API direction. I have many
> years of C/C++ programming under my belt, so I tend to want to micromanage the
> resources. :)

As an example I have done this while rewriting Unix.file_descr for
myself.

My FD is a custom block containing the int. MyUnix.close will set the
int to -1 to signal the FD is no longer valid. MyUnix.read / write /
... throw an exception when the FD is -1. And the finalizer outputs a
warning and closes the FD unless it is -1.

That way I can close FDs when I want them closed and I can not leak an
unclosed FD (although you can still keep it alive forever). I also get a
warning when I forget to close an FD either soon after it dies or at the
end of the program if it was kept alive forever.

MfG
        Goswin


  reply	other threads:[~2010-02-10 21:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-09  3:07 Rich Neswold
2010-02-09  3:38 ` [Caml-list] " Jacques Garrigue
2010-02-09  8:24   ` Miles Sabin
2010-02-09  8:43     ` Jacques Garrigue
2010-02-09 17:18     ` Rich Neswold
2010-02-09  8:31   ` Tiphaine Turpin
2010-02-09 18:09     ` Rich Neswold
2010-02-09 18:45       ` Tiphaine Turpin
2010-02-10  0:39         ` Rich Neswold
2010-02-10  8:55           ` Goswin von Brederlow
2010-02-10 18:00             ` Rich Neswold
2010-02-10 21:37               ` Goswin von Brederlow [this message]
2010-02-09 17:13   ` Rich Neswold
2010-02-09  3:59 ` Yaron Minsky
2010-02-09 17:16   ` Rich Neswold
2010-02-11 10:39   ` Alexey Rodriguez
2010-02-11 11:05     ` rossberg
2010-02-11 13:52       ` Alexey Rodriguez
2010-02-11 15:17         ` rossberg

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=87hbposrf2.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    --cc=rich.neswold@gmail.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).