--- Dave Whipp <[EMAIL PROTECTED]> wrote:
> OK, we've beaten the producer/consumer thread/coro model to death.
> Here's a
> different use of threads: how simple can we make this in P6:
> 
>   sub slow_func
>   {
>           my $percent_done = 0;
>           my $tid = thread { slow_func_imp( \$percent_done ) };
>           thread { status_monitor($percent_done) and sleep 60 until
> $tid.done };
>           return wait $tid;
>   }
> 
> I think this would work under Austin's A17; but it feels a bit
> clunky. The
> fact that the "sleep 60" isn't broken as soon as the function is done
> is
> untidy, though I wouldn't want to start killing thread.
> 
> perhaps:
> 
>   {
>       ...
>       $tid = thread { slow... }
>       status_monitor(\$percent_done) and wait(60 | $tid) until
> $tid.done;
>       return $tid.result;
>   }
> 
> The thing is, that "wait 60" probably can't work -- replace C<60>
> with
> C<$period>, and the semantics change. There are some obvious hacks
> that
> could work here: but is there a really nice solution. Ideally, we
> won't need
> the low level details such as C<$tid>

sub slow_func_imp {
  my $pct_done = 0;
  ...
  yield $pct_done++;   # Per my recent message
  ...
}

sub slow_func {
  my $tid := thread &slow_func_imp;

  status_monitor($tid.resume)
    while $tid.active;
}

    

Reply via email to