Davewhite has asked for the wisdom of the Perl Monks concerning the following question:


Hi All,

I am working on a perl script ( in windows environment ) which uses OLE for interacting with CANAlyzer software ( as COM server ).

I am creating a thread from same script, to perform TeraTerm operations in parallel to script execution.

Unfortunately, the script terminates in between with error: Free to wrong pool XXX not YYY while global destruction, when the thread execution completes.

 Please suggest some resolution or workaround.

 I have read, the CPAN fork module can't be used in windows perl environment

 Eagerly waiting for divine enlightenment from Monk.

Regards Dave

Replies are listed 'Best First'.
Re: free to wrong pool while global destruction : windows perl environment
by jand (Friar) on Jul 27, 2009 at 07:36 UTC
    The Win32::OLE module is not safe for use in threaded Perl. You _may_ be able to get by if you only use Win32::OLE inside a single thread *if* you load Win32::OLE inside that thread. But loading Win32::OLE and then creating additional Perl interpreter threads is going to blow up.

      Thanks for the reply

      My requirement is to create the thread after OLE access in main thread

      Following is my requirement :

      1. Connect to the CANAlyzer using OLE in perl script.

      2. Perform test execution using CANAlyzer, in a loop and start a parallel thread to perform some file processing and save the log for test execution.

      Is there any other approach to perform parallel processing apart from threads.( fork won't work in windows perl )

        fork() does work, somewhat in Windows Perl, but as it is implemented using threads on Windows, it won't work for you because of the same reason that threads don't work for your problem.

        The best way, as jand already described, is to load Win32::OLE in a second thread, and to not have Win32::OLE in the main thread. You will need to restructure your program so it works that way.

        Alternatively, consider having two programs, one that talks to CANAlyzer, and one that talks to TeraTerm. The two programs then can talk to each other through files, pipes (via IPC::Open3 for example), or sockets. This is not trivial either, but might provide a way forward for you.