Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] How to create an idle thread...
[ 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: [Caml-list] How to create an idle thread...
Hi,

I'm having some trouble with the bytecode interpreter, and doing a
proper idle thread for my operating system.

The problem is, if there is no thread to run, the CPU should halt --
asm("hlt") -- and then, when an interrupt fires, this instruction
'returns', letting execution continue on.

However, my problem is that I don't know how to make it idle.

This is the code I have at present (vmthreads/scheduler.c:schedule_thread()):

if (run_thread == NULL) {
    /* then idle... */
    asm("hlt");
    /* process any pending events, since nothing else to do :P */
    caml_process_event();
    /* look for a waiting thread now that an interrupt has fired */
    goto try_again;
}

Interrupts are handled through the signals interface in byterun
(replacing signals).

For some reason, either the interrupt doesn't get processed, or
something else more obscure is happening. What my interrupt handler
does is use the signal interface to call into ocaml land when
appropriate, and run a small bit of ocaml code (wakes up a waiting
thread if there is one waiting for that irq) and return.

Anyone able to shed some light on why this isn't working?

Jonathan