Re: JavaMemoryModel: A problematical case for finalizers

From: Richard Jones (R.E.Jones@ukc.ac.uk)
Date: Thu Apr 10 2003 - 05:59:23 EDT


I admit that I haven't been following this discussion as closely as maybe I
should have been. But some of conclusions drawn worry me from the point of view
of being able to explain to 'ordinary programmers'. I'm willing to bet that
most programmers would accept Bill's example as correct code. I've just tried
the example with some grad students: none of them thought the example was
broken until shown why. Whether explicitly or implicitly, I think they (and
most programmers) accept David's view that "the lifetime of references is
established by the actions of the program and the scopes in which those
references exist".

That model is easy to explain. It may also be easy to explain a synchronised
fix. The key point is that if we want to reduce the volume of broken code that
it written, it's not sufficient simply to declare code as broken or to
construct correct memory model. The result has to be a model that can be easily
assimilated by programmers. Otherwise they will simply continue to write broken
code.

Richard

On Wed, 09 Apr 2003 10:43:32 EDT, Bill Pugh <pugh@cs.umd.edu> wrote:>public
class Foo {
> OutputStream out;
>
> public Foo(...) {
> out = ...;
> }
>
> public void send(...) {
> byte [] buf = ...;
> out.write(buf);
> }
> protected void finalize() {
> out.close();
> }
> }
>
>Now consider the code:
>
> { Foo f = new Foo(...);
> f.send(...);
> }

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:44 EDT