From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p65HqCRf022288 for ; Tue, 5 Jul 2011 19:52:12 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgcDADFOE07RVdi2kGdsb2JhbAA9AQMSmROObggUAQEBAQkJDQcUBCGuX4wmgkyELjmIaAIDBoYwBIc5in2MIzyDXA X-IronPort-AV: E=Sophos;i="4.65,480,1304287200"; d="scan'208";a="112594405" Received: from mail-qy0-f182.google.com ([209.85.216.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Jul 2011 19:52:06 +0200 Received: by qyk38 with SMTP id 38so4343755qyk.6 for ; Tue, 05 Jul 2011 10:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=qX0CtaUOjPWOyFYkDgltWH2+sZrkYqL/hbTVzCpXobk=; b=ZTNyHh1oCEhUNcCjLrv8m8wuMsfuqL1dsVDDEy8ks016+GmrsIqrkpqUQ2QB/8/wB3 YBcICnwgwcZgVgkm42L3auOlPdWa7XNO/qdRbdatJ3rCiP+x7z5M2b7rXybhtsRGjz2q 3erZxtF0VH4sJIfYV5MTfMzQXGV3srjpqPfcE= MIME-Version: 1.0 Received: by 10.229.66.148 with SMTP id n20mr5677811qci.199.1309888325177; Tue, 05 Jul 2011 10:52:05 -0700 (PDT) Received: by 10.229.237.149 with HTTP; Tue, 5 Jul 2011 10:52:05 -0700 (PDT) In-Reply-To: <4E134A89.7070307@inria.fr> References: <4E133C2F.6050202@soton.ac.uk> <4E134A89.7070307@inria.fr> Date: Tue, 5 Jul 2011 21:52:05 +0400 Message-ID: From: Dmitry Bely To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p65HqCRf022288 Subject: Re: [Caml-list] Nested callbacks? On Tue, Jul 5, 2011 at 9:31 PM, Xavier Leroy wrote: > On 07/05/2011 06:30 PM, Thomas Fischbacher wrote: >> >> Dmitry Bely wrote: >> >>> Is it allowed to call a Caml closure from C (caml_callbackN_exn), that >>> calls another Caml closure internally (also with caml_callbackN_exn)? >> >> I strongly hope so! If this did not work, that would have disastrous >> consequences for the tight integration of Caml and Python which we are >> using. (Well, so far, we never encountered a problem with that. And the >> documentation does not warn against doing this - so, should it not work, >> that should be considered a bug.) > > Indeed, it should work, and I see no reason why nested callbacks could > fail.  Callbacks do save some Caml-specific state and restore it > before returning, but they use the stack to do so, so they should be > reentrant.  Please file a bug report if you find out they are not. Thanks. I am trying to find a memory bug in a multithreaded application that calls bytecode Ocaml runtime from C via callbacks. I was able to extract a test that triggers the bug. Actually it's just an endless loop with a single callback inside that only allocates some memory on the Ocaml heap. Interesting enough that when I have only one Caml thread (and no Caml tick thread running), everything goes OK. But when I register 2 threads in Ocaml runtime (one worker, one always sleeping), thus enabling the tick thread and related preempt signal machinery, after many cycles I get a memory bug in the worker thread: Starting new major GC cycle ### O'Caml runtime: heap check ### file freelist.c; line 397 ### Assertion failed: prev < bp || prev == Fl_head (Assertion is failed because prev == bp) As the preempt signal is also processed via Caml callback, I thought the problem might be nested callbacks. But if they are OK - well, I just have to continue debugging. If I find what goes wrong, of course I will file a bug report. - Dmitry Bely