caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Lazy and Threads
@ 2009-02-17 15:54 victor-caml-list
  2009-02-17 20:14 ` [Caml-list] " Yaron Minsky
  0 siblings, 1 reply; 4+ messages in thread
From: victor-caml-list @ 2009-02-17 15:54 UTC (permalink / raw)
  To: caml-list

Hello, 

I'm working with both lazy expressions and threads, and noticed that the 
evaluation of lazy expressions is not thread-safe:

  let expr = lazy (Thread.delay 1.0)

  let _ =
    let thread = Thread.create (fun () -> Lazy.force expr) () in
      Lazy.force expr; 
      Thread.join thread

The second thread to attempt an evaluation dies with Lazy.Undefined. The 
source of this appears to be the standard Lazy.force behavior, which 
replaces the closure in the lazy-block with a raise_undefined closure in 
order to detect self-recursing lazy expressions.

Aside from handling a mutex myself (which I don't find very elegant for 
a read operation in a pure functional program) is there a solution I can 
use to manipulate lazy expressions in a pure functional multi-threaded 
program?

-- 
Victor Nicollet


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-20 23:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-17 15:54 Lazy and Threads victor-caml-list
2009-02-17 20:14 ` [Caml-list] " Yaron Minsky
2009-02-20 18:36   ` Xavier Leroy
2009-02-20 23:01     ` Yaron Minsky

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