Proposal: Automatic Resource Management

Peter Mount peter at retep.org.uk
Sat Mar 7 10:39:31 PST 2009


On Sat, Mar 7, 2009 at 6:28 PM, Neal Gafter <neal at gafter.com> wrote:

> Although I understand this proposal does not address locks (among
> others), holding a lock is most definitely holding a "true resource".
>
> On Sat, Mar 7, 2009 at 10:19 AM, Joshua Bloch <jjb at google.com> wrote:
> > If people feel that the locking case is important, I encourage them to
> > pursue it with another proposal.  I suspect that it won't be difficult to
> > write.  But I am less certain that it will pay for itself.  I believe
> that
> > the cost-benefit ratio for "true resources" is much higher than for
> locks.
> >  When Doug was working on JSR 166 we discussed linguistic support, but he
> > never really felt the need.
>
>
Perhaps we are looking at this in the wrong way?

The current proposal is for Disposable resources by modifying try so it
takes a Disposable expression so for Locks, although they are resources
perhaps this should be an additional proposal done in a similar way but with
try also accepting Lock as the expression?

i.e.

private final Lock lock;

public void doSomething()
{
   try( lock ) {
    // do something within the lock
    }
}

where the try actually calls lock() before the body and unlock() at the end.

If you think this should be a separate but related proposal I'll be happy to
write one.

Peter

-- 
Peter Mount
e: peter at retep.org.uk
w: http://retep.org
Jabber/GTalk: peter at retep.org MSN: retep207 at hotmail.com



More information about the coin-dev mailing list