4

The documentation for Wx::Thread includes a small but instructive example of how to post an event from a child thread to a window in the main or parent thread.

What I cannot understand is how it can possibly be valid to refer to the file-scoped lexical variable $frame from the child thread as illustrated. The sequence of events is as follows: 1) start child thread; 2) initialize $frame; 3) ...time passes...; 4) child thread posts event to $frame.

I had thought that all non-shared variables get cloned when a thread starts. How can $frame be anything but undef in the child thread?

enter image description here

Sue D. Nymme
  • 838
  • 7
  • 8
  • Yeah, that makes no sense. The thread's copy of $frame will be undef since $frame was populated after it was cloned by thread-creation. – ikegami May 03 '16 at 19:25
  • Are they relying on the entry to the function taking longer than the variable declaration? – oldtechaa May 04 '16 at 11:46
  • That won't work unless it's shared. `perl` clones it's entire variable space at thread instantiation, unless it's explicitly shared. – Sobrique May 04 '16 at 13:33

0 Answers0