* [Caml-list] Nested callbacks? @ 2011-07-05 16:06 Dmitry Bely 2011-07-05 16:25 ` Guillaume Yziquel 2011-07-05 16:30 ` Thomas Fischbacher 0 siblings, 2 replies; 8+ messages in thread From: Dmitry Bely @ 2011-07-05 16:06 UTC (permalink / raw) To: Caml List Is it allowed to call a Caml closure from C (caml_callbackN_exn), that calls another Caml closure internally (also with caml_callbackN_exn)? - Dmitry Bely ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 16:06 [Caml-list] Nested callbacks? Dmitry Bely @ 2011-07-05 16:25 ` Guillaume Yziquel 2011-07-05 16:30 ` Thomas Fischbacher 1 sibling, 0 replies; 8+ messages in thread From: Guillaume Yziquel @ 2011-07-05 16:25 UTC (permalink / raw) To: Dmitry Bely; +Cc: Caml List Le Tuesday 05 Jul 2011 à 20:06:58 (+0400), Dmitry Bely a écrit : > Is it allowed to call a Caml closure from C (caml_callbackN_exn), that > calls another Caml closure internally (also with caml_callbackN_exn)? > > - Dmitry Bely I do not see why not. Not 100% sure, but I believe some code of mine did that. -- Guillaume Yziquel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 16:06 [Caml-list] Nested callbacks? Dmitry Bely 2011-07-05 16:25 ` Guillaume Yziquel @ 2011-07-05 16:30 ` Thomas Fischbacher 2011-07-05 17:31 ` Xavier Leroy 1 sibling, 1 reply; 8+ messages in thread From: Thomas Fischbacher @ 2011-07-05 16:30 UTC (permalink / raw) To: Dmitry Bely; +Cc: Caml List 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.) -- best regards, Thomas Fischbacher t.fischbacher@soton.ac.uk ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 16:30 ` Thomas Fischbacher @ 2011-07-05 17:31 ` Xavier Leroy 2011-07-05 17:52 ` Dmitry Bely 0 siblings, 1 reply; 8+ messages in thread From: Xavier Leroy @ 2011-07-05 17:31 UTC (permalink / raw) To: caml-list 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. - Xavier Leroy ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 17:31 ` Xavier Leroy @ 2011-07-05 17:52 ` Dmitry Bely 2011-07-05 18:06 ` rixed 0 siblings, 1 reply; 8+ messages in thread From: Dmitry Bely @ 2011-07-05 17:52 UTC (permalink / raw) To: caml-list 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 17:52 ` Dmitry Bely @ 2011-07-05 18:06 ` rixed 2011-07-05 18:17 ` Dmitry Bely 0 siblings, 1 reply; 8+ messages in thread From: rixed @ 2011-07-05 18:06 UTC (permalink / raw) To: caml-list > file freelist.c; line 397 ### Assertion failed: prev < bp || prev == Fl_head I stumbled upon this one when using threads on a program of mine some time ago on ARM arch (but not others). Do you run your code on ARM by any chance? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 18:06 ` rixed @ 2011-07-05 18:17 ` Dmitry Bely 2011-07-06 9:00 ` Dmitry Bely 0 siblings, 1 reply; 8+ messages in thread From: Dmitry Bely @ 2011-07-05 18:17 UTC (permalink / raw) To: caml-list On Tue, Jul 5, 2011 at 10:06 PM, <rixed@happyleptic.org> wrote: >> file freelist.c; line 397 ### Assertion failed: prev < bp || prev == Fl_head > > I stumbled upon this one when using threads on a program of mine some > time ago on ARM arch (but not others). Do you run your code on ARM by > any chance? No, it's x86. - Dmitry Bely ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Nested callbacks? 2011-07-05 18:17 ` Dmitry Bely @ 2011-07-06 9:00 ` Dmitry Bely 0 siblings, 0 replies; 8+ messages in thread From: Dmitry Bely @ 2011-07-06 9:00 UTC (permalink / raw) To: caml-list Of course I have found my own bug and nested callbacks work as expected. Sorry about the noise in the list. - Dmitry Bely ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-07-06 9:00 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-07-05 16:06 [Caml-list] Nested callbacks? 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 2011-07-05 18:06 ` rixed 2011-07-05 18:17 ` Dmitry Bely 2011-07-06 9:00 ` Dmitry Bely
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox