caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] C function calls OCaml function in multithreads
@ 2015-03-05  2:31 Masateru Kawaguchi
  2015-03-09  1:31 ` Masateru Kawaguchi
  0 siblings, 1 reply; 5+ messages in thread
From: Masateru Kawaguchi @ 2015-03-05  2:31 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 248 bytes --]

Hello,

I'm implementing a C function that calls an OCaml function.

If the C function is called by multithreads, the OCaml function works fine ?
Is that all right when the C function uses mutual exclusion locks ?

Best regards,
Masateru Kawaguchi

[-- Attachment #2: Type: text/html, Size: 397 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] C function calls OCaml function in multithreads
  2015-03-05  2:31 [Caml-list] C function calls OCaml function in multithreads Masateru Kawaguchi
@ 2015-03-09  1:31 ` Masateru Kawaguchi
  2015-03-09  7:36   ` David Allsopp
  0 siblings, 1 reply; 5+ messages in thread
From: Masateru Kawaguchi @ 2015-03-09  1:31 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]

Hello,

I sent a question to caml-list a few days ago, but there is no reply yet.
So let me explain my question in detail.

I have a C program and I'll try to rewrite some libraries of them in OCaml.
The C program runs in multithreads, so the OCaml library will be called by
multithread.
In order to avoid two threads running the OCaml part at one time, I'll try
insert
a code to acquire mutex lock in the C function before calling the OCaml
function.
But I'm not sure that is enough to run the program safely.

Does anyone know about it ?
Please give me some advise about multithreading or how to incorporate OCaml
into C program.

Best regards,
Masateru Kawaguchi

2015-03-05 11:31 GMT+09:00 Masateru Kawaguchi <masateru.k@gmail.com>:

> Hello,
>
> I'm implementing a C function that calls an OCaml function.
>
> If the C function is called by multithreads, the OCaml function works fine
> ?
> Is that all right when the C function uses mutual exclusion locks ?
>
> Best regards,
> Masateru Kawaguchi
>
>

[-- Attachment #2: Type: text/html, Size: 1702 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] C function calls OCaml function in multithreads
  2015-03-09  1:31 ` Masateru Kawaguchi
@ 2015-03-09  7:36   ` David Allsopp
  2015-03-09  9:21     ` Masateru Kawaguchi
  0 siblings, 1 reply; 5+ messages in thread
From: David Allsopp @ 2015-03-09  7:36 UTC (permalink / raw)
  To: OCaml List (caml-list@inria.fr)

Masateru Kawaguchi wrote:
> I sent a question to caml-list a few days ago, but there is no reply yet.
> So let me explain my question in detail.
>
> I have a C program and I'll try to rewrite some libraries of them in OCaml.
> The C program runs in multithreads, so the OCaml library will be called by multithread.
> In order to avoid two threads running the OCaml part at one time, I'll try insert
> a code to acquire mutex lock in the C function before calling the OCaml function.
> But I'm not sure that is enough to run the program safely.
>
> Does anyone know about it ?
> Please give me some advise about multithreading or how to incorporate OCaml into C program.

Chapter 19 of the manual? Especially sections 10 "Advanced topics: multithreading" (http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec465) and 7 "Advanced topics: callbacks from C to OCaml" (http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec448 - see in particular 19.7.4)


David


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] C function calls OCaml function in multithreads
  2015-03-09  7:36   ` David Allsopp
@ 2015-03-09  9:21     ` Masateru Kawaguchi
  2015-03-09  9:43       ` David Allsopp
  0 siblings, 1 reply; 5+ messages in thread
From: Masateru Kawaguchi @ 2015-03-09  9:21 UTC (permalink / raw)
  To: David Allsopp; +Cc: OCaml List (caml-list@inria.fr)

[-- Attachment #1: Type: text/plain, Size: 1728 bytes --]

> Chapter 19 of the manual? Especially sections 10 "Advanced topics:
multithreading" (
http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec465) and 7
"Advanced topics: callbacks from C to OCaml" (
http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec448 - see in
particular 19.7.4)

Thank you for your answer.
I've read the manual. That's what I'd like to know.

Best regards,
Masateru Kawaguchi


2015-03-09 16:36 GMT+09:00 David Allsopp <dra-news@metastack.com>:

> Masateru Kawaguchi wrote:
> > I sent a question to caml-list a few days ago, but there is no reply yet.
> > So let me explain my question in detail.
> >
> > I have a C program and I'll try to rewrite some libraries of them in
> OCaml.
> > The C program runs in multithreads, so the OCaml library will be called
> by multithread.
> > In order to avoid two threads running the OCaml part at one time, I'll
> try insert
> > a code to acquire mutex lock in the C function before calling the OCaml
> function.
> > But I'm not sure that is enough to run the program safely.
> >
> > Does anyone know about it ?
> > Please give me some advise about multithreading or how to incorporate
> OCaml into C program.
>
> Chapter 19 of the manual? Especially sections 10 "Advanced topics:
> multithreading" (
> http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec465) and 7
> "Advanced topics: callbacks from C to OCaml" (
> http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec448 - see in
> particular 19.7.4)
>
>
> David
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

[-- Attachment #2: Type: text/html, Size: 3299 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] C function calls OCaml function in multithreads
  2015-03-09  9:21     ` Masateru Kawaguchi
@ 2015-03-09  9:43       ` David Allsopp
  0 siblings, 0 replies; 5+ messages in thread
From: David Allsopp @ 2015-03-09  9:43 UTC (permalink / raw)
  To: OCaml List (caml-list@inria.fr)

Masateru Kawaguchi wrote:
> David Allsopp wrote:
> > Chapter 19 of the manual? Especially sections 10 "Advanced topics: multithreading"
> > (http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec465) and 7 "Advanced topics:
> > callbacks from C to OCaml" (http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec448
> > - see in particular 19.7.4)
>
> Thank you for your answer.
> I've read the manual. That's what I'd like to know.

Forgive the confusion, but 19.10 of the manual *is* the answer to your question: it describes exactly what you have to do for multiple C threads which to make calls into the OCaml runtime. You need to use caml_c_thread_register/caml_c_thread_unregister and caml_release_runtime_system/caml_acquire_runtime_system. You don't need your own mutex - OCaml already has its own "master lock", as described.


David


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-09  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05  2:31 [Caml-list] C function calls OCaml function in multithreads Masateru Kawaguchi
2015-03-09  1:31 ` Masateru Kawaguchi
2015-03-09  7:36   ` David Allsopp
2015-03-09  9:21     ` Masateru Kawaguchi
2015-03-09  9:43       ` David Allsopp

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