Yes. Thread::Queue works perfectly in conjunction with threads, despite that the naming convention suggests otherwise (something I've bemoaned myself on a few occasions). By way of demonstration, here's a somewhat trivial tk app that starts two worker threads each updating a different gui element via a single queue:
#!perl -slw use strict; use threads; use Thread::Queue; ## A shared var to communicate progess between work thread and TK my $Q = new Thread::Queue; sub work{ my( $id, $delay ) = @_; open PROC, qq[ perl -le"\$|=1; print and select('','','', $delay ) for 1 .. 1 +00" |] or die $!; while( <PROC> ) { $Q->enqueue( "$id:$_" ); } close PROC; } threads->new( \&work, $_, 0.1 * $_ )->detach for 1 .. 2; ## For lowest memory consumption require (not use) ## Tk::* after you've started the work thread. require Tk::ProgressBar; my $mw = MainWindow->new; my $pb1 = $mw->ProgressBar()->pack(); my $lb = $mw->Label( -height => 2 )->pack; my $pb2 = $mw->ProgressBar()->pack(); my $repeat; $repeat = $mw->repeat( 100 => sub { while( $Q->pending ) { my( $id, $progress ) = split ':', $Q->dequeue; return unless $progress; ( $id == 1 ? $pb1 : $pb2 )->value( $progress ); if( $id == 2 && $progress == 100 ) { $repeat->cancel; $mw->exit; } } } ); $mw->MainLoop;
In reply to Re^7: possibility to overcome perl threads
by BrowserUk
in thread possibility to overcome perl threads
by llancet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |