For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2005 > Threads Under Windows









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Threads Under Windows
codewarrior@mail.com

2005-11-03, 6:59 pm

I'm trying to use threads under Perl/TK on Windows XP (Activestate
5.8.7 build 813) and I'm starting to believe it doesn't work. I'm
guessing I should give up until they change something. I get the error:

Attempt to free non-existent shared string '_TK_RESULT_', Perl
interpreter: 0x1b7995c at C:/Perl/site/lib/Tk/Widget.pm line 98 during
global destruction.
Attempt to free non-existent shared string '_XEvent_', Perl
interpreter: 0x1b7995c at C:/Perl/site/lib/Tk/Widget.pm line 98 during
global destruction.
Free to wrong pool 1b785c0 not 222770 at C:/Perl/site/lib/Tk/Widget.pm
line 98 during global destruction.

My simple test code:
#!perl -w
use strict;
use threads;

# Simple tk perl script to post an alert
use Tk;

# Create the window
my $main = new MainWindow;

# Main window
my $b = $main->Button(-text=>'threadit',-command=>\&threadit)->pack;

MainLoop;

sub threadit
{
my $thread = threads->create(\&thethread);
$thread->join;
}
sub thethread
{
}

Dean Arnold

2005-11-03, 6:59 pm

codewarrior@mail.com wrote:
> I'm trying to use threads under Perl/TK on Windows XP (Activestate
> 5.8.7 build 813) and I'm starting to believe it doesn't work. I'm
> guessing I should give up until they change something. I get the error:
>
> Attempt to free non-existent shared string '_TK_RESULT_', Perl
> interpreter: 0x1b7995c at C:/Perl/site/lib/Tk/Widget.pm line 98 during
> global destruction.
> Attempt to free non-existent shared string '_XEvent_', Perl
> interpreter: 0x1b7995c at C:/Perl/site/lib/Tk/Widget.pm line 98 during
> global destruction.
> Free to wrong pool 1b785c0 not 222770 at C:/Perl/site/lib/Tk/Widget.pm
> line 98 during global destruction.
>


FYI: Perl/Tk is *not* threadsafe.

That being said, some of us have successfully used it in a threaded
environment, but it requires that you run Perl/Tk entirely
in its own thread, and use (e.g.) a Thread::Queue object to
interact with it. In addition, you need to spawn your threads
*before* you startup Perl/Tk, due to Perl's thread model (i.e.,
cloning the entire app. context).

If you google this newsgroup for "threads", you should find some
useful examples.

FWIW: I hope to provide an apartment threading wrapper for Perl/Tk
in the near future which should (hopefully) provide the appearance of
thread-safety.

HTH,
Dean Arnold
Presicient Corp.
codewarrior@mail.com

2005-11-03, 6:59 pm

Thank you for the quick reply. I can see my issue is related to
starting TK before the thread. I had avoided the queue solution because
I thought the static data available in my script when the thread
started would be enough for my application. I'll have a look at the
other solutions and have another go at it.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com