Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
calling ocaml from threaded C program
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-01-08 (19:40)
From: Trevor Jim <trevor@r...>
Subject: calling ocaml from threaded C program
I'm having some crashes with a threaded C program that calls
ocaml code.  (Unison on Mac OS X.)

This discussion:

provides some good information, but I could use some more info.
(And I hope this will make it into the manual at some point.)


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


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,