All other threads are called spawned threads. Examples are written in Perl5, and use the thread programming model documented in Thread.pm . All threads see the same compiled subroutines Subroutines are typically defined during the initial compilation of a program. Regardless, at any point in its execution, a program has one and only one collection of defined subroutines, and all threads see this collection. If the user cares which happens first, then they are responsible for doing their own synchronization, for example, with join , as shown in Example 1.
Threads increment the reference count upon entry to a subroutine, and decrement it upon exit.
This ensures that the op tree won't be garbage collected while the thread is executing it. It doesn't matter whether the assignment in foo executes before or after the print in the main thread. As in Perl5, local ized variables are visible to any subroutines called while they remain in scope. Dynamic scopes are not inherited by spawned threads. It is the same variable in both the main thread and the spawned thread.