caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: orbitz@ezabel.com
To: rossberg@mpi-sws.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Scoped Bound Resource Management just for C++?
Date: Wed, 9 Feb 2011 10:15:43 -0500	[thread overview]
Message-ID: <F325FC2E-D852-4A7A-8550-F77797392BD0@ezabel.com> (raw)
In-Reply-To: <77df810e993b3002f8b97622102da8dd.squirrel@mail.mpi-sws.org>

Thanks for the answers everyone.

How does one safely write code in Ocaml that guarantees resources will  
be freed?  Guillaume mentioned the with-idiom, but even that doesn't  
seem entirely safe.

On Feb 9, 2011, at 7:01 AM, rossberg@mpi-sws.org wrote:

>> One of the benefits, in my opinion, of C++ is SBRM.  You can reason
>> about the lifetime of an object and have an give yourself guarantees
>> about its clean up.  The method of initialization and clean up are
>> also consistent for every object in the language.
>
> Don't believe the hype. :) Scope-bound resource management is  
> inherently
> broken, at least without sophisticated type system support. In a
> higher-order language, there are various ways in which objects could  
> escape
> their scope, e.g. closures, references, exceptions. That can only  
> mean one
> of two things for SBRM:
>
> 1) Either it is not actually true, i.e. life times are not actually  
> bound by
> scope in general and you have no actual guarantees,
>
> 2) or it is unsafe, i.e. you can access an object after its life  
> time has
> ended, with potentially desastrous effects.
>
> C++ chose (2), which is out of the question for a safe language. If  
> your
> language makes heavy use of first-class functions (and thus  
> closures) that
> strategy is a particular no-go.
>
> Also, SBRM does not scale at all to concurrency. The underlying  
> assumption
> that all life times are somehow well-bracketed through the dynamic  
> calling
> hierarchy simply doesn't hold anymore when you have shared-state
> concurrency. Getting life times right in concurrent C++ is a  
> nightmare in my
> experience, and often requires synchronizing deallocation in quite
> inefficient ways (thereby effectively making it explicit, and  
> subverting the
> whole idea of tying it to scope implicitly).
>
> /Andreas
>


  reply	other threads:[~2011-02-09 15:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08 23:57 orbitz
2011-02-09  0:46 ` Guillaume Yziquel
2011-02-09  0:48 ` Jacques Garrigue
2011-02-09  6:25 ` dmitry grebeniuk
2011-02-09 12:01 ` rossberg
2011-02-09 15:15   ` orbitz [this message]
2011-02-09 16:14     ` Gerd Stolpmann
2011-02-09 16:52       ` David Rajchenbach-Teller
2011-02-09 17:54         ` orbitz
2011-02-09 21:50           ` Jon Harrop
2011-02-10  8:10           ` David Rajchenbach-Teller
2011-02-10 10:39     ` Guillaume Yziquel
2011-02-10 10:59       ` Guillaume Yziquel
2011-02-09 19:11   ` Florian Weimer
2011-02-09 20:10     ` Andreas Rossberg
2011-02-09 20:45       ` Florian Weimer
2011-02-09 21:12         ` Andreas Rossberg
2011-02-10 21:31           ` Florian Weimer
2011-02-09 18:03 ` Jon Harrop
2011-02-09 20:47 ` Norman Hardy
2011-02-09 21:00   ` Gabriel Scherer

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=F325FC2E-D852-4A7A-8550-F77797392BD0@ezabel.com \
    --to=orbitz@ezabel.com \
    --cc=caml-list@inria.fr \
    --cc=rossberg@mpi-sws.org \
    /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).