Version française
Home     About     Download     Resources     Contact us    
Browse thread
Co-existing with non OCaml threads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ted Kremenek <kremenek@c...>
Subject: Re: [Caml-list] Co-existing with non OCaml threads
Hi Francois,

 From my understanding of OCaml threads, they are non-preemptive user- 
level threads that run within a single kernel thread.  Further, OCaml  
does not employ a concurrent garbage collector; essentially the whole  
program stops (including all OCaml threads) when the garbage  
collector runs.  OCaml threads do not provide any additional actual  
parallelism (they are not preemptive like kernel threads), but like  
all user-level threads they provide an abstraction of parallel  
threads as a programming idiom.  I am not certain if in the  
implementation of OCaml threads that one thread automatically yields  
to another when it calls a blocking operation like an I/O operation  
(like the user-level thread implementation for C described in the  
Capriccio paper that appeared in SOSP a few years ago), but I doubt it.

You might be able to run the OCaml run-time (I am talking about  
native code) within a program that employs multiple kernel threads as  
long as ALL the OCaml code runs in one designated thread, but the run- 
time was not designed to be executed within multiple kernel threads.

Of course I could be completely wrong about this, but this was my  
interpretation from the documentation, previous emails on this list,  
and from my brief circumspection of the code from the OCaml run-time.

Ted

On May 11, 2006, at 5:29 PM, Francois Rouaix wrote:

> I'm contemplating writing an OCaml interface for a C++ middleware  
> library that my company develops and uses internally. Typically  
> this middleware will start an event loop on a thread in the  
> background, leaving the application responsible for its own threads  
> (and potentially using none and having its own code running  
> entirely on events within the eventloop thread).
> How's this likely to be compatible with OCaml use of native threads  
> (this is on Linux by the way)?
> The manual section for interfacing with C isn't mentionning threads  
> anywhere.
> Should Caml code be restricted to run on threads it has created? Or  
> can it run on any threads?
> How can I synchronize between a thread running C++ code and a  
> thread running OCaml code (i.e. both communicating on a message  
> queue)?
> Thanks for any suggestions.
> --f
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs