Perl: the Markov chain saw | |
PerlMonks |
Creating threads inside BEGIN blocksby sonofason (Sexton) |
on May 16, 2006 at 08:14 UTC ( [id://549684]=perlquestion: print w/replies, xml ) | Need Help?? |
sonofason has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone,
In order to avoid copying too much data, it has previously been suggested (Things you need to know before programming Perl ithreads) that threads can be created inside a BEGIN block, before modules not used by the thread are loaded into memory. When you read the documentation for the threads module, however, it states in the list of bugs that: "Creating threads inside BEGIN blocks (or during the compilation phase in general) does not work. (In Windows, trying to use fork() inside BEGIN blocks is an equally losing proposition, since it has been implemented in very much the same way as threads.)" I tried running a simple example (not unlike the one in Things you need to know before programming Perl ithreads), in which I created a thread inside a begin block:
This produced the following output: 1 2 3 4 1111111011 5 6 7 8 9 10 As far as I can tell, the basic functionality seems to be working and running the script didn't generate any warnings on my system (Win XP using ActiveState Perl). Does anyone know what exactly it is that doesn't work with creating threads inside BEGIN blocks? Are there memory leaks after the thread has been terminated, or what is going on? Thanks, sonofason
Back to
Seekers of Perl Wisdom
|
|