caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Wang <philippe.wang@lip6.fr>
To: caml-list@inria.fr
Cc: Philippe Wang <philippe.wang@lip6.fr>
Subject: Re: [Caml-list] "ok with parallel threads" GC (aka ocaml for multicore)
Date: Sat, 18 Apr 2009 00:15:11 +0200	[thread overview]
Message-ID: <5409216D-4094-424B-BEEE-3AC3701A87DD@lip6.fr> (raw)
In-Reply-To: <9E5A9BDB-2A67-45DC-A963-AA45B7E1693B@lip6.fr>


On Apr 16, 2009, at 11:45 CEDT, Philippe Wang wrote:

>> A negative answer would imply that you patched the OCaml
>> runtime to make it reentrant. To illustrate my point, I will take
>> the example of the file "byterun/compare.c". In this file, the
>> code for the comparison of values makes use of a global
>> variable (named "caml_compare_unordered").
>
> It should be, unless bugs are still hiding under that.
> It is supposed to have been done for a while. We'll make one more  
> check.
>
>> If you patched the runtime to allow multiple threads to use
>> it concurrently, I would also be interested by the strategy
>> used: is the problem solved by additional parameters ?
>> by the use of thread-local storage ? by any other mean ?
>
> - local variable instead of global variable in functions
> - some functions are parameterized by thread identifier (that is,  
> one more parameter than "before") (e.g. in amd64.S)

Well, we went back into runtime code implementation.

This is what can be said rapidly :
- compare.c contains no global variables anymore, we use local  
variables instead
- if a Caml-C or C-Caml interface uses caml_compare_unordered, we  
don't know what can happen with parallel threads
- we have many global mutex locks with small scopes
- we do use an "enter/leave blocking section" mechanism to prevent the  
GC from waiting on a blocking operation such as I/O or mutex locking  
etc.
- we don't support weak values (not sure whether they don't work or  
they became strong, if they dont work anymore, they can be back in 2  
minutes as strong values anyway)
- serialisation of values is a little bit tricky, though it should work
- most important : many global variables do not exist anymore because  
they are irrelevant in our implementation
- we do not support unofficial-features of ocaml 3.10, e.g. the new  
features that come with 3.11 but actually have their roots in previous  
versions
~ it is almost sad to see all the based-on-"one-thread-at-a-time"  
optimisations removed...
+ (it looks like it works just fine)


I hope there are no "hidden" bad global variables.

Is it fully reentrant ? Hmmmm... maybe.

We use a stop-the-world GC (which means no one is running is parallel  
with the GC), that is actually like original ocaml, that comes with  
its inconveniences : C calls not declared as blocking sections (which  
has quite a cost) may prevent other threads from running when the heap  
is full.

Graphics module, for instance, is not reentrant at all (anyhow it's  
not part of the runtime). Same for Str.
Funny thing is we can open several windows by launching parallel  
threads (though only one is useful at the end).


Anyway, thank you for your questions and interest, they have helped us  
find&fix some bugs.


--
Philippe Wang
   http://www-apr.lip6.fr/~pwang/


PS.  We tried to switch to 3.11, but it seems to need too much time,  
it's far from being a piece of cake.
We have tried to make it work on Leopard (actually, I failed the 1st  
time - half the way, I may try again if I have time).

=====================================
A free very personal advice that may save you some headaches:
do not program in concurrent shared memory style, especially when you  
can replace "concurrent" by "parallel".
Even if it may have a future, even if it may sound great, even if it  
sounds exciting, even if it helps you go faster, even if <put-here- 
whatever-you-want>,
it is **awful**. Well, if you really really don't have a choice, never  
mind what I said.


  reply	other threads:[~2009-04-17 22:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-10 17:04 Philippe Wang
2009-04-10 20:52 ` [Caml-list] " Jon Harrop
2009-04-10 23:20 ` Jerome Benoit
     [not found] ` <BB3C091F-3BE9-4883-A7CF-9D672CDDF829@x9c.fr>
2009-04-14 10:21   ` Philippe Wang
2009-04-14 14:18     ` xclerc
2009-04-16  9:45     ` Philippe Wang
2009-04-17 22:15       ` Philippe Wang [this message]
2009-04-17 22:20         ` Joel Reymont
2009-04-17 22:29           ` Philippe Wang
2009-04-17 23:05         ` forum
2009-04-23 16:49         ` 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=5409216D-4094-424B-BEEE-3AC3701A87DD@lip6.fr \
    --to=philippe.wang@lip6.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;
as well as URLs for NNTP newsgroup(s).