| zentara 2005-01-15, 8:57 am |
| On Sat, 15 Jan 2005 01:00:37 +0000 (UTC), Steve Lidie
<lusol@Dragonfly.cc.lehigh.edu> wrote:
>zentara <zentara@highstream.net> wrote:
>
>And why? ;) I'm always willing to learn more ...
>
>
>OK, re-phrase: Tk is not thread safe. "can't use them" seemed
>sufficient for a non-Tk group ;) BTW, we're still not in
>comp.lang.perl.tk.
>
>
>Similar to the fork() caveat that the child cannot touch in any way
>parent Tk data structures.
>
>
>Another big reason "we" Tk-ers don't use threads is probably because
>over the last decade their implementation has been a moving target,
>and bug-prone. fork()/exec()/pipe() are better known and better
>tested, etc. It's another idiom to learn, but, I and I'm sure others
>would love to see/hear your experiences on the mailing list and
>newsgroup.
>
>Then maybe the following code would make more sense. Still the "no
>passing objects" rule might be too hard to live with. Can you
>explain more?
Well, for instance, don't try to access a Tk object from one of the
worker threads, like trying to update a $text widget from the thread.
Also, don't try to pass an object to the worker thread, thru a shared
variable, ( which is commonly done in within Tk , like when passing
a widget to a function to tell it where to display the output.)
You can just send scalar numbers and text back and forth through
the shared variables. This is really all you need anyways, even binary
strings could be sent. I havn't tried it, they may need base64 encoding?
Additionally, textvariables, which are defined to
be shared variables, won't automatically update themselves when changed.
So you need to set up a timed mechanism in the Tk GUI,
which periodically reads the shared variables, and updates their
displays.
Just by coincidence I was looking at the gtk2-perl demo for threads,
and they do it exactly the same way. Create the workers before the GUI
creation is done.
I think threads are here to stay and working, if you keep it very
simple.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
|