From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA09702; Tue, 2 Apr 2002 22:17:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA07602 for caml-list@pauillac.inria.fr; Tue, 2 Apr 2002 22:17:13 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA09132 for ; Tue, 2 Apr 2002 10:04:03 +0200 (MET DST) Received: from localhost.home.net ([217.164.67.152]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g3283xX06846 for ; Tue, 2 Apr 2002 10:04:00 +0200 (MET DST) Received: (qmail 883 invoked by uid 1000); 2 Apr 2002 08:02:16 -0000 From: ronniec95@lineone.net Date: Tue, 2 Apr 2002 12:02:16 +0400 To: caml-list@inria.fr Subject: [Caml-list] Interfacing C threads with Ocaml - weird bug Message-ID: <20020402080216.GA845@cradle.net.ae> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.27i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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