Version française
Home     About     Download     Resources     Contact us    
Browse thread
"ok with parallel threads" GC (aka ocaml for multicore)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Philippe Wang <philippe.wang@l...>
Subject: Re: [Caml-list] "ok with parallel threads" GC (aka ocaml for multicore)

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.