caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Trevor Jim <trevor@research.att.com>
To: caml-list@yquem.inria.fr
Subject: calling ocaml from threaded C program
Date: Mon, 08 Jan 2007 14:40:41 -0500	[thread overview]
Message-ID: <45A29E39.9030403@research.att.com> (raw)

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



             reply	other threads:[~2007-01-08 19:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-08 19:40 Trevor Jim [this message]
2007-01-08 21:21 ` [Caml-list] " Markus Mottl
2007-01-08 22:15   ` Trevor Jim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45A29E39.9030403@research.att.com \
    --to=trevor@research.att.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).