caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@gmail.com>
To: victor-caml-list@nicollet.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Lazy and Threads
Date: Tue, 17 Feb 2009 15:14:48 -0500	[thread overview]
Message-ID: <891bd3390902171214s40e4c378sc9c373f6c2822597@mail.gmail.com> (raw)
In-Reply-To: <20090217155455.GA2352@stock.ovh.net>

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

At a minimum, this seems like a bug in the documentation. The documentation
states very clearly that Undefined is called when a value is recursively
forced.  Clearly, you get the same error when you force a lazy value that is
in the process of being forced for the first time....

It does seem like fixing the behavior to match the current documentation
would be superior to fixing the documentation to match the current behavior.

I'd suggest adding a bug report to the bug tracker.

y

On Tue, Feb 17, 2009 at 10:54 AM, <victor-caml-list@nicollet.net> wrote:

> 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
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 2464 bytes --]

  reply	other threads:[~2009-02-17 20:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-17 15:54 victor-caml-list
2009-02-17 20:14 ` Yaron Minsky [this message]
2009-02-20 18:36   ` [Caml-list] " 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=891bd3390902171214s40e4c378sc9c373f6c2822597@mail.gmail.com \
    --to=yminsky@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=victor-caml-list@nicollet.net \
    /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).