first time using threads

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


    I'm stuck at thread as I've just starting using it. I would like to
spawn (and detach) a thread which update a text label in a Tk window. The
following is the code:


use strict;
use warnings;
use Tkx;
use threads;
use threads::shared;

my $k : shared = 0;

my $mw = Tkx::widget->new(".");
   $mw->g_wm_title('Hello World!');

my $mf = $mw->new_ttk__frame();

my $la = $mf->new_ttk__label(-textvariable => $k);

my $thr = threads->new(\&_sub1);


sub _sub1 {
  $k = $k + 1; sleep 1;


I thought the text label would be updated every 1 second. Yet, it gets the
firts update then it does not anymore...what am I doing wrong?


Re: first time using threads

Quoted text here. Click to load it

(I haven't looked at the code.) Do you know Tkx is thread-safe? Tk (that
is,, the old Nick Ing-Simmons perl/tk interface) is known not to
work with threads.


Site Timeline