Browse thread
[Caml-list] Interfacing C threads with Ocaml - weird bug
- ronniec95@l...
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | ronniec95@l... |
| Subject: | [Caml-list] Interfacing C threads with Ocaml - weird bug |
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