From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 08028BC0A for ; Mon, 8 Jan 2007 20:40:47 +0100 (CET) Received: from mail-red.research.att.com (mail-red.research.att.com [192.20.225.110]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l08JekCr013379 for ; Mon, 8 Jan 2007 20:40:46 +0100 Received: from [135.207.240.25] (vpn-25.research.att.com [135.207.240.25]) by bigmail.research.att.com (8.13.7+Sun/8.11.6) with ESMTP id l08Jef9B015716 for ; Mon, 8 Jan 2007 14:40:41 -0500 (EST) Message-ID: <45A29E39.9030403@research.att.com> Date: Mon, 08 Jan 2007 14:40:41 -0500 From: Trevor Jim User-Agent: Thunderbird 1.5.0.8 (X11/20061117) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: calling ocaml from threaded C program Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45A29E3E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 threads:01 threads:01 callbacks:01 posix:01 exn:01 val:01 val:01 wosize:01 runtime:01 api:01 api:01 int:01 caml:02 I'm having some crashes with a threaded C program that calls ocaml code. (Unison on Mac OS X.) This discussion: http://groups.google.com/group/fa.caml/browse_thread/thread/684a6f1647fdbe3/e4ad7e1e8fca5edb?lnk=gst&q=threads&rnum=1#e4ad7e1e8fca5edb provides some good information, but I could use some more info. (And I hope this will make it into the manual at some point.) Specifically: The program is an ObjC program, a GUI wrapped around an ocaml program (Unison). The ObjC program is multithreaded. From the above discussion I realize that only one of the ObjC threads can call back to ocaml at any given time, therefore I have a lock for ocaml callbacks (a posix threads mutex). However, I still get crashes. I think I must be missing some locking. So far I have locked ObjC calls to caml_callback, caml_callback_exn, etc. I have not locked certain other calls of the caml C API, e.g., caml_named_value() caml_copy_string() caml_remove_global_root() caml_register_global_root() Val_int() Field() String_val() Wosize_val() If anyone knows exactly what parts of the ocaml C API need to be locked for this scenario, it would be nice to have that in the documentation. Also, I wonder whether there is any issue with having one ObjC thread in the ocaml runtime, while another ObjC thread accesses an object that is either an ocaml root or accessible from an ocaml root -- is any locking required? Thanks for any info, Trevor