On 8/8/06, why the lucky stiff <ruby-core / whytheluckystiff.net> wrote:
> 1. Ruby uses setitimer to switch threads. I would like to use setitimer as well
> to abort a sandbox which runs longer than its timeout. Can anyone recommend a
> signal which can be used for this? Or could I get access to the thread
> switching routine so I can check sandbox timeouts between threads? Or, perhaps
> there is another strategy.
I'm not sure if I'm about to repeat what Charles has already said, but
how about you add a structure inside the interpreter loop that gets a
value added to it whenever a timed sandbox starts up (and removed
whenever it completes)? There can be multiple sandbox timeouts active
at a time, so you can do this from multiple green threads. The
structure contains the real time at which each timeout expires, and
the associated thread descriptor. Add something to the interpreter
loop that runs down the expired timeouts every time through, and
raises a Ruby exception to each expiring sandbox. It's heavyweight
because of the kernel-lock needed to check the time but maybe Ruby is
already doing that somewhere else.