From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 27081BC37 for ; Tue, 27 Oct 2009 11:01:24 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArEEALth5krVujhf/2dsb2JhbACBUNZjhD8E X-IronPort-AV: E=Sophos;i="4.44,632,1249250400"; d="scan'208";a="39021060" Received: from witko.kerneis.info ([213.186.56.95]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-SHA; 27 Oct 2009 11:01:23 +0100 Received: from alf94-4-82-224-79-17.fbx.proxad.net ([82.224.79.17] helo=hokahe.kerneis.info) by witko.kerneis.info with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1N2iri-0002ba-9U; Tue, 27 Oct 2009 11:01:22 +0100 Received: from gabriel by hokahe.kerneis.info with local (Exim 4.69) (envelope-from ) id 1N2iri-0000zs-L4; Tue, 27 Oct 2009 11:01:22 +0100 Date: Tue, 27 Oct 2009 11:01:22 +0100 From: Gabriel Kerneis To: yoann padioleau Cc: Till Varoquaux , caml-list@inria.fr Subject: Re: [Caml-list] threads, signals, and timeout Message-ID: <20091027100122.GD2792@kerneis.info> Mail-Followup-To: yoann padioleau , Till Varoquaux , caml-list@inria.fr References: <9d3ec8300910261136w3cee8329od4b0a02365cde8db@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-SA-Exim-Connect-IP: 82.224.79.17 X-SA-Exim-Mail-From: gabriel@kerneis.info X-SA-Exim-Scanned: No (on witko.kerneis.info); SAEximRunCond expanded to false X-Spam: no; 0.00; ocaml:01 ocaml:01 event-driven:01 monadic:01 compiler:01 26,:98 2009:98 threads:01 threads:01 wrote:01 pps:01 pps:01 caml-list:01 jussieu:01 jussieu:01 On Mon, Oct 26, 2009 at 12:06:18PM -0700, yoann padioleau wrote: > I want to write a toy program that uses threads and timeouts in an > easy way. Those threads may make heavy use of CPU or IO, I don't know. > I just want an easy API for thread and timeout. > > To be honest, the problem I have to solve is not in OCaml, but I > thought OCaml programmers would give better answers than C programmers Looks like CPC[1] is the perfect tool for you: cooperative threads in C, with the ability to "detach" a thread for CPU intensive operations (i.e. make it a native preemptive thread), compiled to sequential event-driven C code (using continuations). In other words, this is some kind of Lwt for C, with a thread API (instead of the monadic API of Lwt). But the timeout problem remains: we have a strong feeling that cooperative threads is the right way to go, and that you should not be interrupted anywhere (especially in C, where you don't have any GC to clean-up your malloc'ed variables, file descriptor, etc.). So you have to be explicit about where the timeouts can happen, e.g. polling (cooperatively) some condition variable. We are trying to improve the timeouts handling in CPC at the moment, so we would be glad to get more details on what you are trying to do exactly, and how we could solve it. A sample implementation of timeouts can be found in the io.cpc file of the Hekate BitTorrent seeder[2]. Since this becomes a bit off-topic, I have to mention the fact that the compiler is written in OCaml (upon the CIL library) ;-) [1] http://www.pps.jussieu.fr/~jch/software/cpc/ [2] http://www.pps.jussieu.fr/~jch/software/hekate/ NB: please keep in mind that CPC is a research prototype, suitable for a "toy program" like yours, or even serious ones like Hekate, but it would not be reasonable to develop industrial software with it at the moment. Regards, -- Gabriel Kerneis