caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] caml_callback_depth : byterun + vmthreads
@ 2005-12-18  2:48 Jonathan Roewen
  2005-12-18  3:11 ` Jonathan Roewen
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Roewen @ 2005-12-18  2:48 UTC (permalink / raw)
  To: caml-list

Hi,

I found this bit of code in vmthreads/scheduler.c:

/* Don't allow preemption during a callback */
if (callback_depth > 1) return curr_thread->retval;

I've done some grepping, and I can find one instance of
[caml_]callback_depth++ (as far as I can tell, this is done once
only), and two instances of [caml_]callback_depth--. These are both in
byterun/interp.c. No where else is this value modified that I can
find, which has got me baffled.

It is the check above that is killing my OS (it never schedules
another thread). This also happens randomly.

Can some one please explain what the hell is going on?

Jonathan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] caml_callback_depth : byterun + vmthreads
  2005-12-18  2:48 [Caml-list] caml_callback_depth : byterun + vmthreads Jonathan Roewen
@ 2005-12-18  3:11 ` Jonathan Roewen
  2005-12-18  4:20   ` Jonathan Roewen
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Roewen @ 2005-12-18  3:11 UTC (permalink / raw)
  To: caml-list

My bad :-) Functions in callback.c can recursively call the interpreter.

So, now gives the problem of tracking which callback calls another
callback, that calls the scheduler, and doesn't end up doing anything
;-)

Jonathan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] caml_callback_depth : byterun + vmthreads
  2005-12-18  3:11 ` Jonathan Roewen
@ 2005-12-18  4:20   ` Jonathan Roewen
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Roewen @ 2005-12-18  4:20 UTC (permalink / raw)
  To: caml-list

> So, now gives the problem of tracking which callback calls another
> callback, that calls the scheduler, and doesn't end up doing anything
> ;-)

Well, I've tracked it down to byterun/signals.c I think:

/* Execute a signal handler immediately */

void caml_execute_signal(int signal_number, int in_signal_handler)
{
  value res;
  res = caml_callback_exn(
           Field(caml_signal_handlers, signal_number),
           Val_int(signal_number));
  /* do I need to add this? I think so... */
  caml_pending_signals[signal_number] = 0;
  if(signal_number < 16) {
      if(signal_number > 7)
        out8(0xa0,0x20);
      out8(0x20,0x20);
    }
  if (Is_exception_result(res)) caml_raise(Extract_exception(res));
}

So, am I right that what is happening is that: caml_interprete
processes signals, calls a callback (callback_depth now == 2), that
caml code tries to schedule another thread, and can't.

Now field is one of these two functions:

[vmthreads/thread.ml]
(* Preemption *)

let preempt _ =
  if !critical_section then () else thread_request_reschedule()

[kernel/interrupts.ml]
let irq_handler irq =
  if waiting.(irq) = [] then (
    recv.(irq) <- true
  ) else (
    List.iter (fun t -> Thread.wakeup t) waiting.(irq);
  );
  waiting.(irq) <- [];;

thread_request_reschedule doesn't do any callbacks, and neither does
Thread.wakeup's C implementation part.

Now I'm more confused than ever: this shouldn't be possible....

Well, this is all valid results from `grep "callback" -R .':

./byterun/finalise.c:#include "callback.h"
./byterun/finalise.c:      caml_callback (f.fun, f.val);

./byterun/printexc.c:#include "callback.h"
./byterun/printexc.c:  if (at_exit != NULL)
caml_callback_exn(*at_exit, Val_unit);

./byterun/signals.c:#include "callback.h"
./byterun/signals.c:  res = caml_callback_exn(

Any tips on tracking down this monster of a problem?

Jonathan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-18  4:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-18  2:48 [Caml-list] caml_callback_depth : byterun + vmthreads Jonathan Roewen
2005-12-18  3:11 ` Jonathan Roewen
2005-12-18  4:20   ` Jonathan Roewen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).