|Do you know where your variables are?|
Tk and thread local storageby nikosv (Hermit)
|on Nov 15, 2010 at 06:30 UTC||Need Help??|
nikosv has asked for the
wisdom of the Perl Monks concerning the following question:
More like playing around with the TLS model rather than any practical value, I wanted to look into what happens with threads and tk in more detailed way.
So I have a window in the main thread with a buttons and when the button is clicked I fire a thread from within the callback. Of course ill advised since tk is not thread safe but done for demonstration purposes only.
What happens is that the $mw and the window structure get duplicated (but there is no window to be seen) in the worker thread but they both share the same window handle:
There two distinct HASH references sharing the same window handle ($mw->id) but when I manipulate the worker thread window like changing its title $mw->title("Worker thread window") the title of the Main thread window is changed since they reference the same window handle. I am specullating that since the handle is a kernel object it does not get copied.
In fact if you continue clicking the button you will see getting more copies of the window but always with the same handle. Checked with Data:Dumper($mw) too and it is consistent that we get a totally distinct structure each time. So when using threads from within TK we get distinct copies of the window struct but all sharing the same handle
I am asking for some aid in verifying the validity of this test and if someone could shed more light into the internals/what is actually happenning