RE: help sharing Tk::Photo object

[email protected] ("Jerry D. Hedden")
Newsgroups perl.ithreads
Message-ID <20060608115410.fb30e530d17747c2b054d625b8945d88.80945739df.wbe@email.secureserver.net>
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.8.8/ext/threads/shared/shared.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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.