caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Tom Ridge <tom.j.ridge+caml@googlemail.com>
To: Yaron Minsky <yminsky@janestreet.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Thread behaviour
Date: Sun, 29 Sep 2013 17:25:04 +0100	[thread overview]
Message-ID: <CABooLwOD2zHpL8qgqH5D-6s+j4LEHma2KPXH00A+m9z5r_WCAw@mail.gmail.com> (raw)
In-Reply-To: <CACLX4jRJ=sSu9T0Kj+cg_Mu7zYDTewa54e5tTnYERphtgv75wA@mail.gmail.com>

On 29 September 2013 13:37, Yaron Minsky <yminsky@janestreet.com> wrote:
> I think you've come away with the wrong conclusion.  Here's my summary
> of the state of play.
>
> OCaml has a single runtime lock, but _does_ support pre-emptive OS
> threads.  You can use them for concurrency but not parallelism.  Code
> that runs in a tight loop in one thread, though, can starve another
> thread, particularly if it doesn't allocate, because OCaml only gives
> up the runtime lock when it allocates.

OK, but this means that I can't think of OCaml code running in
different threads in a simple way - I have to consider the single
runtime lock at least (if I care about performance). So maybe the
question is: how should I understand the functioning of the single
runtime lock? For example, is starvation the only thing I need to
think about?

>
> You should probably avoid direct use of threads for concurrent
> programming.  Monadic concurrency libraries like lwt or async are the
> way to go.  You can definitely build message-passing libraries on top
> of these, and many have.

Could you provide some pointers to these libraries? I would be very
interested in this. One thing I didn't immediately see how to do, when
reading the Lwt docs, was to provide a user interface (connect, send,
recv etc) that did not expose the fact that co-operative threads were
in the background. It also seems to me that if someone uses my library
with their code, and their code itself uses Lwt, then there is the
possibility for strange interactions (my Lwt threads are not isolated
from their Lwt threads; with system threads and system-provided
pre-emptive scheduling, you (maybe) do get some isolation/fairness
properties).

>
> You can also build such libraries against raw threads, but I would recommend.
>
> None of which is to argue that you shouldn't use a binding of some
> non-OCaml message-passing library.  I've heard excellent things about
> zeromq,which has bindings in opam.

OK! So +1 for zeromq. I will check it out. Any votes for any other
libraries? OCamlMPI?

BTW thanks to everyone for taking the time to respond to these
questions, and apologies for my ignorance.

T

  reply	other threads:[~2013-09-29 16:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 10:10 Tom Ridge
2013-09-27 10:22 ` Simon Cruanes
2013-09-27 10:27 ` Romain Bardou
2013-09-27 10:51   ` Benedikt Grundmann
2013-09-28 19:09     ` Tom Ridge
2013-09-29  7:54       ` Tom Ridge
2013-09-29 12:37         ` Yaron Minsky
2013-09-29 16:25           ` Tom Ridge [this message]
2013-09-29 16:46             ` Chet Murthy
2013-09-29 17:18               ` Tom Ridge
2013-09-29 17:47                 ` Chet Murthy
2013-09-30  8:24                   ` Romain Bardou
2013-10-07 14:57                     ` Goswin von Brederlow
2013-09-30  8:16       ` Romain Bardou
2013-10-01  3:32         ` Ivan Gotovchits
2013-10-07 14:49       ` Goswin von Brederlow
2013-09-30  9:18 ` Xavier Leroy
2013-09-30 15:12   ` Tom Ridge
2013-09-30 16:01     ` Török Edwin
2013-09-30 16:56     ` Gabriel Kerneis
2013-09-30 18:18       ` Alain Frisch
2013-10-01  5:01   ` Pierre Chambart
2013-10-01  7:21     ` Gabriel Kerneis
2013-10-02 10:37     ` Wojciech Meyer
2013-10-02 11:52       ` Francois Berenger
2013-10-02 11:58         ` Wojciech Meyer

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=CABooLwOD2zHpL8qgqH5D-6s+j4LEHma2KPXH00A+m9z5r_WCAw@mail.gmail.com \
    --to=tom.j.ridge+caml@googlemail.com \
    --cc=caml-list@inria.fr \
    --cc=yminsky@janestreet.com \
    /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).