Hi all,
Now I was able to make the same error in the small Perl + Perl/Tk code.
if I dont do detach here
my $thr = threads->new(\&run)->detach;
then this program will eat memory and as I used it here I got this error
Free to wrong pool 1c7a920 not 224f08 at .../Tk/Widget.pm line 98
during global destruction.
What I am doing wrong and what does this error means ??
Any help is appreciated.
Thanks,
aashish
#!/usr/bin/perl -w
#// warning: this app kills the cpu somewhat dead, needs a more
#// sensitive sleep in mainloop handle with care on slow machines,
threads-> yield
#// makes it a bit lighter but still, use caution
use strict;
use Tk;
use threads;
use threads::shared;
use POSIX;
#// For debugging
$|=1;
#// Constructing a new window
my $mw = new MainWindow('title'=>"Tiitel");
my $clockdisplay = $mw->Label;
$clockdisplay->pack('-side'=>'top');
#// For changing the clock value ;-)
my $clockstr : shared ;
$clockstr = 0;
#// indicates when to stop
my $running : shared = 1;
#// starting the other thread which should change our title
clocker();
predixLoop();
#// This loops the tk events and refreshes the window inner things
like buttons etc.
#// it blocks until the window is closed
#// program ending ;0
#$running = 0;
#// SUBS
#// the main thread loop tries to handle event, DoOneEvent(2) means that
#// any action should be takin (from tcl.h) TCL_DONT_WAIT
#// or smth like that , exits the same way as Tk::MainLoop
sub predixLoop {
my $oldclockval = "0";
while(Tk::MainWindow->Count) {
Tk->DoOneEvent(2);
# nice
if ($clockstr != $oldclockval) {
$oldclockval = $clockstr;
$clockdisplay->configure('-text'=>$oldclockval);
}
threads->yield();
}
}
# the child thread running loop
# updates the clock after every 1 sec
sub clocker {
print "clocker starting \n";
if($running)
{
print " I am running: \n";
$running = 0;
my $thr = threads->new(\&run)->detach;
print " After the thread is created: \n";
}
print "child out \n";
}
sub run
{
my $count = 0;
while($count ne 10){
print " The count is: ".($count)."\n";
$clockstr = time();
$count = $count + 1;
sleep(1);
threads->yield();
}
print " This thread will exit: \n";
lock $running;
$running = 1;
}