caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques-Henri Jourdan <jacques-henri.jourdan@ens.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Marshalling: automatic discard of unmashalable data via ephemerons
Date: Wed, 16 Oct 2013 16:03:18 +0200	[thread overview]
Message-ID: <525E9CA6.609@ens.fr> (raw)
In-Reply-To: <20131014153023.GA19032@birba.invalid>

[-- Attachment #1: Type: text/plain, Size: 926 bytes --]

Hi,

Le 14/10/2013 17:30, Enrico Tassi a écrit :
> let collect k = HT.remove values !k
> 
> (* The only reference to the boxed key is the one returned, when the user drops
>    it the value eventually disappears from the values table above *)
> let create (v : 'a) : 'a key =
>   let k = mk_key () in
>   HT.add values !k (Obj.repr v);
>   Gc.finalise collect k;
>   k


In that piece of code, you should take care to the fact that the
finalizer can be called at /any/ moment.

In particular, it can be called while you are modifying your hash table.
If this situation happens, then you are modifying the hash table (by
removing elements) when it is in an unconsistent state.

Did you think about that ? Do I miss something ?

The authors of Why3 encountered similar problems. I suggest you to read
the Weakhtbl module, that gives a solution to this problem.

Regards,
-- 
Jacques-Henri Jourdan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 555 bytes --]

  reply	other threads:[~2013-10-16 14:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-14 15:30 Enrico Tassi
2013-10-16 14:03 ` Jacques-Henri Jourdan [this message]
2013-10-16 14:42   ` Enrico Tassi
2013-10-16 15:30     ` François Bobot
2013-10-16 16:24       ` Alain Frisch
2013-10-22  9:38 ` [Caml-list] Marshalling: automatic discard of unmashalable data via oleg

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=525E9CA6.609@ens.fr \
    --to=jacques-henri.jourdan@ens.fr \
    --cc=caml-list@inria.fr \
    /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).