From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 538287EEAF for ; Tue, 22 Jan 2013 19:57:37 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of smimram@gmail.com) identity=pra; client-ip=209.85.220.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="smimram@gmail.com"; x-sender="smimram@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of smimram@gmail.com designates 209.85.220.180 as permitted sender) identity=mailfrom; client-ip=209.85.220.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="smimram@gmail.com"; x-sender="smimram@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vc0-f180.google.com) identity=helo; client-ip=209.85.220.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="smimram@gmail.com"; x-sender="postmaster@mail-vc0-f180.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai4BAIDf/lDRVdy0m2dsb2JhbABEhkW3WwgWDgEBAQEBCAkLCRQngkgEGQEbHgMSCQEGNwIkAREBBQFQh2sBAw+bYoJwi2VPgXGBCoR4ChknDVmIdgEFDI4BghaBEwOWDI5oFimEGA X-IronPort-AV: E=Sophos;i="4.84,516,1355094000"; d="scan'208";a="191165179" Received: from mail-vc0-f180.google.com ([209.85.220.180]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 22 Jan 2013 19:57:36 +0100 Received: by mail-vc0-f180.google.com with SMTP id fo13so2185494vcb.11 for ; Tue, 22 Jan 2013 10:57:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=KBh4Pt74nbF48uQfw1RtdF4ZySJUL+FyGG2oqoQIHkI=; b=WUKHGu/8ZCbbMoRz5i1APkENiuyG6hojsbCOvEEX6es+krppMwl4128f3UKQlAhPTs oRWI0vFAR/otxDsOe2toEkdzgymTMA3/rC1EkAQ2CNoqluDZR0U1cEVRBRsOj+9NGOSv WVxqwCy4/FzdGr6Id26ahFWEPx5FeFdtylIUgRJB28nPgiiDx+BAZaY9/tq5vy3mS9vY rdN7QQpP/XKA2zxnEAw6VzQK+gC9uy9IfRl8V6+KWtuCCD+uvwlXoNv/xzboX623YfD4 C1Lu6GIVXxuwSLFcoAUV2d/N2TyYdPDDUwzEqvCWdafSPkiddaDNBY0CFIDbW5tFF/Vu HVxg== X-Received: by 10.52.69.176 with SMTP id f16mr21507440vdu.97.1358881055535; Tue, 22 Jan 2013 10:57:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.58.247.137 with HTTP; Tue, 22 Jan 2013 10:57:15 -0800 (PST) From: Samuel Mimram Date: Tue, 22 Jan 2013 19:57:15 +0100 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=20cf307f3aa09b736a04d3e526de X-Validation-by: smimram@gmail.com Subject: [Caml-list] Portable timeout function --20cf307f3aa09b736a04d3e526de Content-Type: text/plain; charset=UTF-8 Hi, I would like to implement 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. Of course, there is a simple implementation using Unix.setitimer, but apparently it does not work under windows because of signals implementation (and I don't have access to a windows machine...). Since this is a pretty standard idom I expected to find it implemented in some library, but could not find one. Also, I'd rather not heavily change the code (i.e. monadic threads are not really an option here, and a small function would be appreciated). Extra points if your solution also works with js_of_ocaml! :) Thanks! Regards, Samuel. --20cf307f3aa09b736a04d3e526de Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

I would like to implement a &= quot;timeout" function of type:

f= loat -> ('a -> 'b) -> 'a -> 'b option

which takes a maximum number n of seconds to run, a fu= nction f, an argument x, and returns Some (f x) if the computation ends bef= ore n seconds and None otherwise. Of course, there is a simple implementati= on using Unix.setitimer, but apparently it does not work under windows beca= use of signals implementation (and I don't have access to a windows mac= hine...). Since this is a pretty standard idom I expected to find it implem= ented in some library, but could not find one. Also, I'd rather not hea= vily change the code (i.e. monadic threads are not really an option here, a= nd a small function would be appreciated).

Extra points if your solution also works wi= th js_of_ocaml! :)

Thanks!

Regards,

Samuel.
--20cf307f3aa09b736a04d3e526de--