Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Is Weak.get guaranteed to return Some until finalisation is executed?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] Is Weak.get guaranteed to return Some until finalisation is executed?
On Friday, November 14, 2003, at 11:07 PM, Aleksey Nogin wrote:

> Currently the documentation for the Weak module seems to imply that 
> the Weak.get can return None whenever it feels like it. Is there any 
> guarantees as to when things are required to stay in the weak array?

It is not documented, mostly because the documentation doesn't introduce
the notions needed to talk about sharing, pointers, and liveness of
data.  It would be nice to do it, in order to give some precise
specification of (==), weak pointers, and finalisation.  But it is
a large amount of work, as the corresponding theoretical work doesn't
exist (as far as I know), and we should carefully avoid over-specifying.

>  In particular, if I call GC.finalise on a heap-allocated value and 
> then stick a value into a weak array, can I be sure that Weak.get will 
> return   Some until after the finalisation function is executed (and 
> finishes its execution)?

Definitely not.  Weak pointers are erased first, and finalisation
functions are called afterward.  When the finalisation function is
called, it really has the only existing pointer to the value.

-- Damien

-------------------
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