English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
RE: [Caml-list] Pattern matcher no more supposed to warn on non exhaustive patterns ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-10-04 (04:29)
From: Gregory Morrisett <jgm@c...>
Subject: RE: [Caml-list] Pattern matcher no more supposed to warn on non exhaustive patterns ?
The issue with threads is a bit more troublesome.  Consider:

  let x : (int->int) option ref = ref (Some (fun x -> x));;

  let foo z =
      match z with
        {contents=None} -> 0
      | {contents=Some(f)} -> f(0);

Now suppose I fork two threads:

Thread 1:  foo x
Thread 2:  x := None

And suppose that Thread 1 runs long enough that it does the first
match, so it assumes the contents of x is not of the form None.  
Now Thread 1 gets descheduled, Thread 2 runs, and sets the
contents of x to None.  Then Thread 2 continues with the second

The question is, does Caml core dump because the pattern matcher
assumes that the contents *has* to be a Some(-) in the second
case?  Or does it do the derefence and check atomically?  Or
does it add a default case that raises a Match exception?  

The same thing shows up in SML/NJ with CML.  The problem is that
in the presence of threads, you really shouldn't be able to 
dereference a mutable value in your patterns.

Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr