That means you can't just rely on MainLoop magically stepping aside to check on your other threads, nor can you fiddle with Tk's structures from an external thread. You'll need to add a repeat timer event before calling MainLoop, and use queues to pass commands/data back and forth.
Here's some (untested) code snippets to get you going.
#!/usr/bin/perl -w use threads; use Thread::Queue; use Tk; use strict; my $cmdq = Thread::Queue->new(); my $respq = Thread::Queue->new(); my $thrd = threads->create(\&image_loader); my $mw = MainWindow->new; # ...the usual widget building here... my $repeat_id = $mw->repeat($interval, \&image_handler); $cmdq->enqueue('GO'); MainLoop; sub image_handler { return unless $respq->pending; my $buffer = $respq->dequeue(); ...load into your frame here... $cmdq->enqueue('GO'); } # # assumes your image loader persists # sub image_loader { while (1) { my $go = $cmdq->dequeue(); last if ($go eq 'STOP'); ...do your image loading business here... $respq->enqueue($imagebuffers); } }
In reply to Re: How to not wait for a thread
by renodino
in thread How to not wait for a thread
by Sixtease
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |