I'm trying to speed up some conversions from html to wordXML by using threads. I was hoping it would be fairly straightforward to spawn several threads with Microsoft word running from each one, but my code for threads throws errors:
use strict; use threads; use Win32::OLE; my $threadNum = 2; my $directoryLocation = 'C:\Users\nate\Desktop\websites';# opendir(DIR, $directoryLocation); my @files = grep(/\.html$/,readdir(DIR)); closedir(DIR); my @threads; my $counter = 0; for(1..$threadNum){ my @fileSlice = @files[$counter..$counter+$#files/$threadNum]; push @threads, threads->create(\&convertToWord,@fileSlice); $counter += $#files/$threadNum+1; } $_->join for(@threads); sub convertToWord(){ my $Word = Win32::OLE->new('Word.Application', 'Quit'); #convert some stuff to wordXML here, not shown to save space }
Actually, the line about starting Microsoft word isn't needed to make the program fail. The perl interpreter crashes and prints the following:
Free to wrong pool 25f3778 not 213fd8 during global destruction.
When I say crash, I don't mean that the program just exits early, I mean that a window pops up telling me that the Perl Command Line Interpreter has stopped working. Any suggestions?
In reply to How to use Threads by nglenn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |