Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^2: Explicit thread contextby jdhedden (Deacon) |
on May 23, 2006 at 16:46 UTC ( [id://551200]=note: print w/replies, xml ) | Need Help?? |
Why are you forced to specify in advance the context that you'll be using?As threads execute asynchronously, the context must be set before the thread starts executing because it may call wantarray at any time during its execution, and may even finish before a ->join() call is made on it. Prior to threads v1.31, the context would be determined by how the ->create() call was made. This lead to the following counter-intuitive syntax if you wanted the threads object, but were expecting to get a list back from the thread: Additionally, this Perl bug has threads created in void context, but then tries to get return values from the thread. With threads 1.31, you can now specify the context directly so as to avoid such confusion:
Does threads throw an assertion error if you accidentally use a different context than the one you promised you'd use?No, but you may not get the results you expect. Remember: There's always one more bug.
In Section
Meditations
|
|