caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Kerneis <kerneis@pps.jussieu.fr>
To: yoann padioleau <pad.aryx@gmail.com>
Cc: Till Varoquaux <till@pps.jussieu.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] threads, signals, and timeout
Date: Tue, 27 Oct 2009 11:01:22 +0100	[thread overview]
Message-ID: <20091027100122.GD2792@kerneis.info> (raw)
In-Reply-To: <c55bbbbc0910261206s53e21e53pe772d72297f83335@mail.gmail.com>

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


  parent reply	other threads:[~2009-10-27 10:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26 18:08 yoann padioleau
2009-10-26 18:36 ` [Caml-list] " Till Varoquaux
2009-10-26 19:06   ` yoann padioleau
2009-10-26 22:14     ` Gerd Stolpmann
2009-10-27 10:01     ` Gabriel Kerneis [this message]
2009-10-26 23:13 ` Philippe Wang

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=20091027100122.GD2792@kerneis.info \
    --to=kerneis@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    --cc=pad.aryx@gmail.com \
    --cc=till@pps.jussieu.fr \
    /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).