Jeremy, Thanks. What you said makes sense. I think I misunderstood the funptr argument but it is very clear now.
I saw that "Advanced topic: multithreading". Given that the library I'm linking in -- libuv -- spawns the threads itself we will need to be creative about getting them to call the caml register function. That's next on my list. Thanks! Trevor On Tue, Dec 2, 2014 at 12:07 PM, Jeremy Yallop <[email protected]> wrote: > On 2 December 2014 at 13:25, Trevor Smith <[email protected]> > wrote: > > 1) C-function in thread A will be called from OCaml, and places an OCaml > > callback cb onto a queue. > > 2) C-function in thread B will asynchronously receive the callback on the > > queue, do some computation, then run cb. > > > > My understanding is that I need to re-acquire the runtime lock when cb is > > ran in thread B. Is that correct? > > Yes. You should be able to use the "runtime_lock" argument to funptr > to indicate that the lock should be (re)acquired when calling back > into OCaml from C: > > > https://github.com/ocamllabs/ocaml-ctypes/blob/e190603a4/src/ctypes-foreign-threaded/foreign.mli#L53 > > https://github.com/ocamllabs/ocaml-ctypes/blob/e190603a4/src/ctypes-foreign-threaded/foreign.mli#L72-L74 > > You probably also need to call caml_c_thread_register() from your C > code to register the thread that's going to be calling back into > OCaml: > > http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual033.html#toc151 > > (It's worth reading that whole "Advanced topic: multithreading" > section of the OCaml manual, if you haven't already.) > > > Also, my understanding is that the lock > > calls are _not_ reentrant, so the acquire/release set are needed. > > Right. >
_______________________________________________ Ctypes mailing list [email protected] http://lists.ocaml.org/listinfo/ctypes
