caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: victor-caml-list@nicollet.net
To: caml-list@inria.fr
Subject: Lazy and Threads
Date: Tue, 17 Feb 2009 16:54:55 +0100	[thread overview]
Message-ID: <20090217155455.GA2352@stock.ovh.net> (raw)

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


             reply	other threads:[~2009-02-17 15:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-17 15:54 victor-caml-list [this message]
2009-02-17 20:14 ` [Caml-list] " Yaron Minsky
2009-02-20 18:36   ` Xavier Leroy
2009-02-20 23:01     ` Yaron Minsky

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=20090217155455.GA2352@stock.ovh.net \
    --to=victor-caml-list@nicollet.net \
    --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).