Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Dmitry Bely <dmitry.bely@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Nested callbacks?
Date: Tue, 5 Jul 2011 21:52:05 +0400	[thread overview]
Message-ID: <CAMT7qiSmi-1Ps2pkFzL-YQ0ik0Vy7HtvJMWbTunvKvcxFy5kmA@mail.gmail.com> (raw)
In-Reply-To: <4E134A89.7070307@inria.fr>

On Tue, Jul 5, 2011 at 9:31 PM, Xavier Leroy <Xavier.Leroy@inria.fr> 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


  reply	other threads:[~2011-07-05 17:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05 16:06 Dmitry Bely
2011-07-05 16:25 ` Guillaume Yziquel
2011-07-05 16:30 ` Thomas Fischbacher
2011-07-05 17:31   ` Xavier Leroy
2011-07-05 17:52     ` Dmitry Bely [this message]
2011-07-05 18:06       ` rixed
2011-07-05 18:17         ` Dmitry Bely
2011-07-06  9:00           ` Dmitry Bely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMT7qiSmi-1Ps2pkFzL-YQ0ik0Vy7HtvJMWbTunvKvcxFy5kmA@mail.gmail.com \
    --to=dmitry.bely@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox