From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DB65DBB91 for ; Thu, 20 Jan 2005 19:23:16 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0KINGLB005648 for ; Thu, 20 Jan 2005 19:23:16 +0100 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 TAA08134 for ; Thu, 20 Jan 2005 19:23:16 +0100 (MET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.206]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0KINFq4028433 for ; Thu, 20 Jan 2005 19:23:15 +0100 Received: by rproxy.gmail.com with SMTP id y7so8320rne for ; Thu, 20 Jan 2005 10:23:15 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:date:from:to:subject:message-id:mail-followup-to:mime-version:content-type:content-disposition:user-agent; b=D3clwKyBojSgYV6FnveMSN7IYQ2TYzAXzsRRI5jKXBUahXgaypb+CL3PnONYz60Ix8mhQVq8uKXJw/fcz+nuH/YizF853lTKVUWc9E/JsdAPVyFAdlP011klETTUJuJR1TzgBWOl2pLlNGG3dwM/C0AtFt6gPGWyI+6xKcXmuUY= Received: by 10.39.3.57 with SMTP id f57mr141771rni; Thu, 20 Jan 2005 10:23:14 -0800 (PST) Received: from localhost ([141.155.88.179]) by smtp.gmail.com with ESMTP id 64sm3583rna.2005.01.20.10.23.14; Thu, 20 Jan 2005 10:23:14 -0800 (PST) Date: Thu, 20 Jan 2005 13:23:13 -0500 From: Markus Mottl To: OCaml Subject: C-threads & callbacks Message-ID: <20050120182313.GB4919@quant3.janestcapital.quant> Mail-Followup-To: OCaml Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Miltered: at concorde with ID 41EFF714.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41EFF713.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 interfacing:01 threads:01 ocaml-code:01 ocaml-code:01 ocaml:01 mutexes:01 error-prone:01 ocaml:01 afaik:01 callbacks:01 callbacks:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.0 X-Spam-Level: Hi, I'm currently interfacing a 3rd-party library that spawns threads to execute callbacks. I would like those callbacks to be handled by OCaml-code, but have run into some issues here. As it seems, it is not possible to run OCaml-code linked with thread support while letting C-threads perform callbacks. This has already been a topic on the list a while ago. I have two solutions in mind: the first one would involve pre-spawning an OCaml-thread and pass data from C to OCaml through an OCaml-reference exposed to C, protected by mutexes and condition variables. This seems pretty ugly, because it's error-prone and also involves a considerable amount of context-switching, which is bad for my application (very high volume realtime data). The second solution would require setting up an OCaml thread descriptor for the currently executing C-thread. However, AFAIK this solution cannot be implemented without fiddling with the implementation of the OCaml-runtime, because some global variables for thread-handling are not exposed to user code (i.e. "static"). It would be great if the thread implementation offered functions allowing users to have their C-threads "migrate" to OCaml. Does anybody know of another elegant and efficient solution for this problem that does not require hacking the OCaml-runtime? Best regards, Markus