Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Interfacing C threads with Ocaml - weird bug
[ Home ] [ Index: by date | by threads ]
[ Search: ]

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

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; 

value ml_queue_dispatch(value queue)
	/* This is called from OCAML and never returns */

/* 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.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: