From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E2F12BB83 for ; Sat, 13 May 2006 11:30:19 +0200 (CEST) Received: from smtp6-g19.free.fr (smtp6-g19.free.fr [212.27.42.36]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k4D9UJYV015054 for ; Sat, 13 May 2006 11:30:19 +0200 Received: from [192.168.1.2] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp6-g19.free.fr (Postfix) with ESMTP id 6FEB720689; Sat, 13 May 2006 11:30:19 +0200 (CEST) Message-ID: <4465A727.6080702@inria.fr> Date: Sat, 13 May 2006 11:30:15 +0200 From: Xavier Leroy User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: francois@rouaix.org Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Co-existing with non OCaml threads References: In-Reply-To: X-Enigmail-Version: 0.91.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 4465A72B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 threads:01 interfacing:01 interfacing:01 threads:01 caml's:01 threading:01 callbacks:01 caml's:01 threading:01 gerd:01 stolpmann:01 subtleties:01 ocaml:01 caml-list:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hi François, > [Interfacing Caml code with multithreaded C/C++ code] > 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? It depends whether your Caml code is single-threaded or multi-threaded. Case 1: The Caml code is single-threaded (more precisely: it is not linked with Caml's threading library). For instance, Caml provides a number of functions that you will call back from the main C/C++ multithreaded program. In this case, you can call back Caml code from any thread. All you need to make sure is that you never call back from two threads concurrently. Just put a lock around the callbacks and you're done. Case 2: The Caml code is linked with Caml's threading library. Then, you can only call back from threads created by Caml, and as Gerd Stolpmann mentioned, there are additional subtleties to ensure mutual exclusion. I'd recommend you avoid this scenario. > How can I synchronize between a thread running C++ code and a thread > running OCaml code (i.e. both communicating on a message queue)? If your message queue is already implemented in C++, all you need to do is wrap the "put" and "get" operations of the message queue using the Caml foreign-function interface, and call these functions from your Caml code. Hope this helps, - Xavier