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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.