English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2009-04-17 (23:05)
From: forum@x9c.fr <forum@x...>
Subject: Re: [Caml-list] "ok with parallel threads" GC (aka ocaml for multicore)

Le 18 avr. 09 à 00:15, Philippe Wang a écrit :

> 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.

I was indeed mostly worried with the runtime itself. I wanted to have  
a fully reentrant runtime for the OCaml-Java
project (to be able to execute several programs in the very same JVM)  
and remember that it implied primitives
from "compare.c", "hash.c", "intern.c" and "extern.c" among others to  
be written differently for this purpose.

Out of curiosity: you state that your GC is of "stop-the-world"  
nature, what about finalizers ?
Are they executed by the GC thread when the world is stopped or  
concurrently with
application threads ?
Not sure this question really matters, just curious (I mean, it is  
doubtful that one would write finalizers with
a long execution time).

Keep up the good work !

Xavier Clerc