Frazier, Joe Jr wrote:
I would have though that targeting a bug-fix only release for
a month's time might be realistic. I'd like to get the
following done:
- fix as many of the trackers as possible
- get all the current sample code to work properly
- include all the examples from the tutorial (and check that
they all work :-), fixing the tutorial as necessary
- work on the test suite
- get a semi-decent web-page up as our Homepage at SourceForge.
Hey, if possible, can someone come up with an example of using Win32::GUI with one or more background worker thread(s)?
Here's my threads example that I'm working on - funnily I was just
discussing it off-list.
#!perl -w
use strict;
use warnings;
use Win32::GUI;
use threads;
use Thread::Queue;
# Win32::GUI is not very thread friendly, so ensure the worker thread
# is created before you create any Win32::GUI objects
print "Boss: Starting\n";
print "Boss: creating queues\n";
my $qd = Thread::Queue->new();
my $qu = Thread::Queue->new();
print "Boss: creating worker thread\n";
my $t = threads->new(\&worker);
my $working = 0; # set by the boss when the worker is working
my $instruction = 1;
my $W = new Win32::GUI::Window (
-pos => [100,100],
-size => [200,200],
-name => "MW",
) or die "Creating main window";
$W->AddButton (
-text => "Execute Thread",
-name => "But1",
) or die "Creating Button1";
# Timer is used to read results back from worker thread
$W->AddTimer( "Tim1", 1000) or die "Creating Timer";
$W->Show();
Win32::GUI::Dialog();
# tidy up
print "Boss: Sending kill to worker\n";
$qd->enqueue(undef);
print "Boss: About to wait for worker\n";
my $r = $t->join();
print "Boss: worker completed after executing $r instructions\n";
exit(0);
sub But1_Click
{
$W->But1->Disable();
print "Boss: Button Clicked: starting worker ($instruction)\n";
$qd->enqueue($instruction++);
$working = 1;
return 1;
}
sub MW_Terminate
{
if($working) {
print "Boss: Can't exit while worker is working\n";
return 0;
}
return -1;
}
sub Tim1_Timer
{
#print "Boss: timer went off\n";
if(my $val = $qu->dequeue_nb()) {
print "Boss: worker finished instruction $val\n";
$W->But1->Enable();
$working=0;
}
return 1;
}
# The worker thread entry point
sub worker
{
print "Worker: starting\n";
my $count = 0;
print "Worker: waiting for instructions\n";
while(my $num = $qd->dequeue()) {
print "Worker: got instruction $num\n";
$count++;
for my $i (0..5) {
print "Worker:doing work ($i)\n";
sleep(1);
}
print "Worker: Done instruction $num\n";
$qu->enqueue($num);
}
print "Worker: Terminating after $count instructions\n";
return $count;
}
__END__
It wouldn't take much to turn it into a proper example. Does this seem like
the right way to do it?
Something I would like to see for example would be a "list" of sites in say a
Win32::GUI::Grid (or listview at worst case, if we want to not use extensions in the
examples) with one or more threads that periodically(using a 20 second timer for example)
connect to the sites and measure response times to populate another column on the Grid.
Interesting idea - again it wouldn't be very difficult
I have seen one or two examples on the list for using threads, but it would be
nice to have one in the core distribution.
Also, has anyone created a PPM for this release yet? If so, is it available on a repository, or only on the sourceforge site for download?
There's a PPM in the bribes repository
(http://www.bribes.org/perl/ppmdir.html#ap)
|ppm install http://www.bribes.org/perl/ppm/Win32-GUI.ppd
(I haven't tested it)
I am also in dialog with ActiveState, and it *should* get in their
repository on their next build cycle (which was supposed to be last
Tuesday night, but it doesn't look like it happened yet)
Rob.
|