On Thursday, May 29, 2003, at 10:47 AM, Dave Whipp 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:
Hey, good example. Hmm...
Well, for starters I think it wouldn't be a big deal to associate a "progress" attribute with each thread object. It should be that thread's responsibility to fill it out, if it wants to -- so you shouldn't ever have to pass \$percent_done as an argument, it should be a basic attribute of every thread instance. That might encourage people to add progress calculations to their threads after-the-fact, without changing the basic interface of what they wrote.
I'll also claim that I would still prefer the auto-parallel, auto-lazy-blocking behavior on the thread results we've mused about previously. So coming from the semantics end, I'd love to see it written like this:
# Declaring a threaded calculation
sub slow_func_impl is threaded {
while (...stuff...) {
... do stuff ...
&_.thread.progress += 10.0; # or however you want to guesstimate[*] this
}
return $result;
}
# If you don't care about getting the actual thread object, just the result,
# call it this way:
{ ... my $result = slow_func_impl(...); ... return $result; }
# But if you want to get the thread object, so you can monitor it's progress,
# call it this way:
{ ... 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.
MikeL
[*] Huh. Imagine my surprise to find out that my spellcheck considers "guesstimate" to be a real word. And I always thought that was just a spasmostical pseudolexomangloid.