Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] caml_callback_depth : byterun + vmthreads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jonathan Roewen <jonathan.roewen@g...>
Subject: Re: [Caml-list] caml_callback_depth : byterun + vmthreads
> 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