From: ronniec95@lineone.net
To: caml-list@inria.fr
Subject: [Caml-list] Interfacing C threads with Ocaml - weird bug
Date: Tue, 2 Apr 2002 12:02:16 +0400 [thread overview]
Message-ID: <20020402080216.GA845@cradle.net.ae> (raw)
Hi guys,
I've written a Ocaml interface for an C-API. It sets up some parameters
(all works) then starts a thread pool (C). I then call a mainloop
function that contains a while loop that, upon receiving a request
dispatches the event to a C callback.
OCAML:
let receiver () =
let _ = Tib.opent ()
and tport = Tib.create_transport "" "" ""
and queue = Tib.default_queue () in
let event = Tib.create_listener queue "testcb" tport "foo" in
print_string "Listening...\n"; flush stdout;
(* This call loops and never returns - but should dispatch events to some callback *)
Tib.queue_dispatch queue;
C:
value ml_queue_dispatch(value queue)
{
/* This is called from OCAML and never returns */
while(tibrvQueue_Dispatch(TIBRV_DEFAULT_QUEUE));
}
/* This function is called from the above dispatcher on an event - it's
* called on a thread taken from a pool (not same as dispatcher/caml.
* Note there is no call back to Caml here */
static void caml_callback_interface(tibrvEvent event,tibrvMsg msg,void* closure)
{
printf("Callback called!\n");
}
Question: Why would it take in the order of 20-30 seconds for the
callback to be triggered rather than immediate as is the case when I've
written identical wrappers for perl/java/C++. I'm guessing something
about thread yielding control, but this should happen automatically
since it uses pthreads internally?
I've tried putting the Tib.queue_dispatch call in its own thread
(started by CAML) or having a new C thread created when the C function
is called, but both show identical symptoms. This is a proprietary API
so I have no access to the raw socket or thread dispatching that goes
on. However I do know it is standard posix threads being created inside
the C code.
Any ideas (very) helpful.
Thanks
Ronnie
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next reply other threads:[~2002-04-02 20:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-02 8:02 ronniec95 [this message]
[not found] ` <15531.9799.220007.210452@akasha.ijm.jussieu.fr>
2002-04-03 17:20 ` ronniec95
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=20020402080216.GA845@cradle.net.ae \
--to=ronniec95@lineone.net \
--cc=caml-list@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