No such thing as a small change | |
PerlMonks |
Explicit thread contextby jdhedden (Deacon) |
on May 23, 2006 at 12:58 UTC ( [id://551148]=perlmeditation: print w/replies, xml ) | Need Help?? |
Version 1.31 of the threads module has been uploaded to CPAN. This
version adds the capability to specify the context to be used for the
->join() call.
THREAD CONTEXT
As with subroutines, the type of value returned from a thread's entry point function may be determined by the thread's context: list, scalar or void. The thread's context is determined at thread creation. This is necessary so that the context is available to the entry point function via wantarray(). The thread may then specify a value of the appropriate type to be returned from ->join(). Explicit context Because thread creation and thread joining may occur in different contexts, it may be desirable to state the context explicitly to the thread's entry point function. This may be done by calling ->create() with a parameter hash as the first argument: In the above, the threads object is returned to the parent thread in scalar context, and the thread's entry point function foo will be called in list context such that the parent thread can receive a list from the ->join() call. Similarly, if you need the threads object, but your thread will not be returning a value (i.e., void context), you would do the following: The context type may also be used as the key in the parameter hash followed by a true value:
Implicit context If not explicitly stated, the thread's context is implied from the context of the ->create() call:
Remember: There's always one more bug.
Back to
Meditations
|
|