From: Romain Bardou <romain.bardou@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Thread behaviour
Date: Mon, 30 Sep 2013 10:24:01 +0200 [thread overview]
Message-ID: <52493521.4000204@inria.fr> (raw)
In-Reply-To: <1402586.FfBdj3Dhrj@groupon>
Le 29/09/2013 19:47, Chet Murthy a écrit :
>
>> This is my situation. I don't care if the code runs on a single core
>> (in fact, I hope it does), but I do want to use threads which are
>> scheduled reasonably independently and reasonably fairly. My first
>> example shows that one thread is effectively starved by the other
>> thread.
>
> Ah. ok. In this case, it's easier. You just need to ensure that in
> every loop,in every recursive function, there's a call to something
> that yield()s, on every path. It's that simple, and that icky. But
> then, if you have code that literally doesn't do anything that yields,
> in a loop, it's compute-intensive, and -that- means you're not really
> asking for concurrency, are you?
>
> BTW, to your original question "why should the while loop affect
> scheduling of f's thread": because there is a global operation
> (scheduling) that needs cooperation from all threads in order to
> execute. And that requires explicit coding by the programmer. Now,
> the compiler -could- have inserted code to do the yield() (in some old
> LISPms, it was done at every backward jump and return, I think).
>
> I can't speculate as to why it wasn't done, but given that the goal of
> ocaml's threads is concurrency, and not parallelism, it isn't common
> (at least, in my experience) to write code that doesn't naturally
> reach yield points frequently.
Unfortunately there is a huge class of such kind of code: code which
uses libraries which do not yield. For instance, code which loads a DLL
to communicate with hardware and which may block (or worse).
Cheers,
--
Romain Bardou
next prev parent reply other threads:[~2013-09-30 8:24 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
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 [this message]
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=52493521.4000204@inria.fr \
--to=romain.bardou@inria.fr \
--cc=caml-list@inria.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