|Anonymous | Login | Signup for a new account||2015-09-04 20:51 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0004721||OCaml||OCaml standard library||public||2009-02-19 13:03||2012-07-27 12:52|
|Priority||normal||Severity||feature||Reproducibility||have not tried|
|Target Version||Fixed in Version|
|Summary||0004721: Lazy is not threadsafe|
|Description||As reported on the caml-list by Victor Nicollet. This code:|
let expr = lazy (Thread.delay 1.0)
let _ =
let thread = Thread.create (fun () -> Lazy.force expr) () in
throws Lazy.Undefined. The documentation indicates that Lazy.Undefined is thrown when multiple recursive calls are made to Lazy.force, but clearly threads can trigger the same behavior.
It would be lovely if Lazy.force was threadsafe (i.e., if the second call simply blocked until the first call was complete). In the absence of that, I think the documentation should be updated to indicate that Lazy.t is not threadsafe.
|Tags||No tags attached.|
My suggestion would be to replace the internal raise_undefined in:
Obj.set_field (Obj.repr blk) 0 raise_undefined;
with a function that remembers the thread it was created in and only raises Undefined within its owner thread : otherwise, it blocks until the value is computed by the original thread and then recursively performs the equivalent of Lazy.force on the value again.
This creates light overhead (since the closure that contains the thread identifier has to be created when evaluating the lazy block) but avoids having to wrap the entire force_lazy_block in a critical section (only the initial set_field has to be wrapped).
> I think the documentation should be updated to indicate that Lazy.t is not threadsafe.
I'd rather change the documentation to indicate that nothing is thread-safe except when explicitly noted.
I have documented the fact that Lazy.force is not thread-safe. Keeping this PR as a feature wish in case we find a good idea to make it thread-safe without too much overhead.
|2009-02-19 13:03||yminsky||New Issue|
|2009-02-20 14:34||vnicollet||Note Added: 0004840|
|2009-03-16 15:34||doligez||Note Added: 0004858|
|2009-04-29 15:41||doligez||Status||new => assigned|
|2009-04-29 15:41||doligez||Assigned To||=> doligez|
|2010-05-12 16:54||doligez||Note Added: 0005452|
|2010-05-12 16:54||doligez||Severity||minor => feature|
|2012-07-27 12:52||frisch||Category||OCaml general => OCaml standard library|
|Copyright © 2000 - 2011 MantisBT Group|