|Anonymous | Login | Signup for a new account||2014-08-20 22:32 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0005908||OCaml||OCaml standard library||public||2013-01-27 17:19||2013-01-28 09:56|
|Priority||normal||Severity||feature||Reproducibility||have not tried|
|Target Version||Fixed in Version|
|Summary||0005908: Add a timeout function to the standard library|
I have tried to program a "timeout" function in a *portable* way but did not succeed with the current standard library. Since this is quite a commonly used idiom, it might be worth adding such a function to the standard library.
I wanted a "timeout" function of type:
float -> ('a -> 'b) -> 'a -> 'b option
which takes a maximum number n of seconds to run, a function f, an argument x, and returns Some (f x) if the computation ends before n seconds and None otherwise. I have tried the following:
- the simple implementation using Unix.setitimer / Unix.alarm does not work under windows because of signals implementation
- the caml-list suggested using Gc.create_alarm which is portable, but really imprecise (we cannot predict when a gc will occur)
- I could have used threads and Thread.kill, but unfortunately Thread.kill is not implemented with the native compiler
- this could be achieved with monadic threads, but I would rather not change the structure of my whole program
|Tags||No tags attached.|
The bottom line of the discussion on caml-list is that such a "timeout" function cannot be implemented correctly on non-Unix platforms, esp. Windows, but also JS-of-OCaml. So, probably, what you're asking for is impossible.
There might be a way to partially emulate Unix.setitimer under Windows, creating a separate thread that posts pseudo-signals periodically. However, such pseudo-signals will not interrupt blocking I/O operations and will only be processed when the OCaml code polls for pending signals. This might be good enough for some applications, but certainly not all.
|2013-01-27 17:19||smimram||New Issue|
|2013-01-28 09:56||xleroy||Note Added: 0008806|
|2013-01-28 09:56||xleroy||Status||new => resolved|
|2013-01-28 09:56||xleroy||Resolution||open => suspended|
|Copyright © 2000 - 2011 MantisBT Group|