Ace128 has asked for the wisdom of the Perl Monks concerning the following question:
@thread_subs is an array of subrefs containing all subs(refs) a surtain plugin wanna start up as a new thread.foreach (keys %plugins) { my $thread_queue = Thread::Queue::Any->new; my @thread_subs; $plugins{$_}->SUBS_AS_THREADS(\@thread_subs, $thread_queue); foreach my $sub (@thread_subs) { async { $sub->($plugins{$_}, \%plugins, $thread_queue, $mw) }; } } ... ... MainLoop;
As you can see, I found this solution quite nice, since I use Tk, and wanna use threads. Since I dunno how many threads a plugin wanna start (and more importantly, IF a plugin wanna start a thread), I have a sub that sets refrences into an array to subs a surtain thread wanna have as threads (@thread_subs).sub _thread_sub_in_a_plugin { my $self = shift; my $plugins_ref = shift; my $thread_queue = shift; my $mw = shift; #$self->{'thread_queue'} = $thread_queue; $$plugins_ref{'imagePlugin'}->{'thread_queue'} = $thread_queue; # The 2 above same thing, really... while (1) { my ($full_path) = $thread_queue->dequeue; ... } }
Ideas? Comments? Suggestions?Main(Tk) imagePlugin | | |------------* | | | generate and show image | |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk and Threads (again)
by zentara (Cardinal) on Jan 22, 2006 at 16:34 UTC | |
|
Re: Tk and Threads (again)
by renodino (Curate) on Jan 22, 2006 at 16:27 UTC | |
by Ace128 (Hermit) on Jan 22, 2006 at 18:30 UTC | |
by renodino (Curate) on Jan 22, 2006 at 22:54 UTC | |
by Ace128 (Hermit) on Jan 23, 2006 at 22:48 UTC | |
|
Re: Tk and Threads (again)
by Errto (Vicar) on Jan 22, 2006 at 19:25 UTC | |
by BrowserUk (Patriarch) on Jan 22, 2006 at 22:45 UTC | |
by Errto (Vicar) on Jan 23, 2006 at 03:28 UTC | |
by BrowserUk (Patriarch) on Jan 23, 2006 at 08:01 UTC | |
by Courage (Parson) on Jan 23, 2006 at 16:50 UTC | |
| |
|
Re: Tk and Threads (again)
by zentara (Cardinal) on Jan 23, 2006 at 16:02 UTC | |
by Ace128 (Hermit) on Jan 23, 2006 at 23:46 UTC | |
by zentara (Cardinal) on Jan 24, 2006 at 10:54 UTC |