On Thursday, May 29, 2003, at 12:45 PM, Dave Whipp wrote:
"Michael Lazzaro" <[EMAIL PROTECTED]> wrote in> # But if you want
to get the thread object, so you can monitor it's
    {
        ...
        my $tid = thread &slow_func_impl(...);
        while $tid.active {
            status_monitor($tid.progress);
            sleep 60;
        }
        return $tid.result;
    }

To my eye, that looks pretty darn slick.

You might be a bit frustrated if the &slow_func_impl took 61 seconds :-(.
How do we interrupt the C<sleep>? Possibly in the same way as we'd timeout a
blocking IO operations.

Personally, I'd be happy with just making the C<sleep> a smaller number, like one second, or a fifth of a second, or whatever. You want the status_monitor to be updated no more often than it needs to be, but often enough that it's not lagging.


But if you really wanted wake-immediately-upon-end, I'd add that as a variant of C<sleep>. For example, you might want a variant that blocked until a given variable "changed", just like in debuggers; that would allow:

{
my $tid = thread &slow_func_impl(...);
while $tid.active {
status_monitor($tid.progress);
sleep( 60, watch => \($tid.progress) ); # do you even need the '\'?
}
return $tid.result;
}


... which would sleep 60 seconds, or until the .progress attribute changed, whichever came first.

You could make more builtins for that, but I think I'd like them to just be C<sleep> or C<wait> variants. Obvious possibilities:

    sleep 60;                 # sleep 60 seconds
    sleep( block => $tid );   # sleep until given thread is complete
    sleep( watch => \$var );  # sleep until given var changes value

sleep( 60, block => $tid, watch => [\$var1, \$var2, \$var3] ); five tests

$tid.sleep(...); # sleep the given thread, instead of this one


MikeL




Reply via email to