in reply to Re: Win32::OLE and fork causes null pointer exception
in thread Win32::OLE and fork causes null pointer exception

Ok, so with Threads the same problem exists:

use strict; use warnings; use Thread; use Win32::OLE; Win32::OLE->Option(Warn => 3); my $thread = Thread->new(\&TEST_THREAD, ("arg1", "agr2")); my $rc = $thread->eval; print $rc; print "\nI'm ending now.\n"; sub TEST_THREAD{ my ($arg1, $arg2) = (@_); return "$arg1\t$arg2"; }


Using threads does throw a more informative error to STDERR though, in addition to the null pointer exception:
Free to wr0ng pool lbaXXXX not XXXXXX during global destruction.
where XXXX and XXXXXX are both hex values.

So it looks like you were right about it being a problem with the global destructor...Is there no way to use Win32::OLE with a multi-threaded script?

I tried moving the use statement for Win32::OLE into TEST_THREAD without any success. If I comment out the use statement for Win32::OLE, the script runs without error.

Replies are listed 'Best First'.
Re^3: Win32::OLE and fork causes null pointer exception
by erroneousBollock (Curate) on Nov 15, 2007 at 16:15 UTC
    Try require rather than use, either:
    • in the new Thread, or
    • in the main thread below the call to threads->new.

    If it doesn't work at all (once we've tried all the standard work-arounds), I'd say you could call it a bug in Win32::OLE.

    -David

      This looks promising...the test script at least runs now with a combination of import and require in the thread subroutine. Thanks for your help!
        For the record, using require and import appears to work with fork as well as with Threads.
        Just a follow-up...unfortunately Win32::OLE will not work in any multi-threaded application. I dug around and found a forum with a post by the author indicating this was a known limitation that may be addressed in the future, but would require a significant amount of work. For my current needs, I split the one script into two separate scripts.