For Programmers: Free Programming Magazines  


Home > Archive > ithreads > June 2006 > help sharing Tk::Photo object









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 help sharing Tk::Photo object
Brent Baccala

2006-05-30, 4:17 am

Hello,

I'm having problems writing my first ithreads program.

I need a Tk::Photo object shared between threads. The idea is
to load images in background while the GUI keeps running.

Can it be done?

As soon as I do a &share($fimage), I can no longer do anything
useful with $fimage. I get complaints like:

Use of uninitialized value in subroutine entry at
/usr/lib/perl5/Tk/Submethods.pm line 37.
image "" doesn't exist at /usr/lib/perl5/Tk/Submethods.pm line 37.

$fimage is a blessed object reference.

I'm running a pretty stock Debian "edge" system, Perl 5.8.8.

Here's a test program that shows my pain.
Usage is "program imagefile".

Thank you for any help you can give.



#!/usr/bin/perl -w

use strict;

use Tk;
use Tk::JPEG;
use threads;
use threads::shared;

my $file = shift;

my $mw = MainWindow->new();
my $fimage = $mw->Photo(-file => $file);

# THIS MAKES ALL THE DIFFERENCE
# &share($fimage);

print $fimage->width, "\n";




-bwb

Brent Baccala
cosine@freesoft.org
Jerry D. Hedden

2006-06-17, 8:59 am

Brent Baccala asked:
> I need a Tk::Photo object shared between threads. The idea is
> to load images in background while the GUI keeps running.
>
> Can it be done?


If the Tk::Photo module (and hence Tk::Image, and so on) is not thread
safe, then you won't be able to share the object between threads.

> As soon as I do a &share($fimage), I can no longer do anything
> useful with $fimage. I get complaints like:
>
> Use of uninitialized value in subroutine entry at
> /usr/lib/perl5/Tk/Submethods.pm line 37.
> image "" doesn't exist at /usr/lib/perl5/Tk/Submethods.pm line 37.


Yes. This is a known aspect of threads::shared. See
http://annocpan.org/~NWCLARK/perl-5...red.pm#note_395

Most likely you'll need to change your application to pass data to the
thread (e.g., the image name) so that the thread can do the work using
its own (non-shared) objects.



Sponsored Links







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

Copyright 2008 codecomments.com