Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Win32::OLE and fork causes null pointer exception

by erroneousBollock (Curate)
on Nov 15, 2007 at 15:12 UTC ( [id://650987]=note: print w/replies, xml ) Need Help??


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

fork() on Win32 is emulated using threads.

threads.pm clones all non-shared variables into new threads.

When they go out of scope, their destructors are called as usual. That can cause bad things to happen for resources like filehandles and Win32 resource handles.

Does anyone know of a workaround for this problem?
Don't use fork() on Win32 under any circumstances. Use threads directly.

-David

  • Comment on Re: Win32::OLE and fork causes null pointer exception

Replies are listed 'Best First'.
Re^2: Win32::OLE and fork causes null pointer exception
by jrsimmon (Hermit) on Nov 15, 2007 at 16:10 UTC
    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.
      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://650987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found