Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Perl crashs always during global destruction when using WIN32 OLE object in multithread

by seven_shen (Acolyte)
on Mar 03, 2011 at 07:15 UTC ( [id://891158]=perlquestion: print w/replies, xml ) Need Help??

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

I meet per crash problem during global destruction while using WIN32 OLE object in multi thread, here is my code:

use strict; use threads; use threads::shared; our$oleobject; $oleobject=Win32::OLE->new("AutoItX3.Control"); my $aut =threads->new(\&check_popup,"check_popup_thread"); $aut->detach(); MYFunction(); exit(0); sub check_popup { require Win32::OLE; my $name =@_; print $name; while(1) { if($oleobject->WinWait('POPUP','',1); { $oleobject->WinClose('POPUP'); } } }

while when the program exits, perl always crash with notice like:

Free to wrong pool 16435b8 not 537ab18 at <eval 40> line 1 Attemt to free unreferenced scalar: SV0x5488e94,Perl interpreter:0x..... during global destruction.

and still lots of error shows : Win32::OLE<0.1709>:GetOleObeject<> Not a Win32::OLE object at C:/Perl/lib/Win32/OLE/Lite.pm line 154

I appreciate your kind help!

  • Comment on Perl crashs always during global destruction when using WIN32 OLE object in multithread
  • Download Code

Replies are listed 'Best First'.
Re: Perl crashs always during global destruction when using WIN32 OLE object in multithread
by Corion (Patriarch) on Mar 03, 2011 at 08:08 UTC

    It is highly unlikely that using threads and Win32::OLE together will work.

    If at all, you should only require Win32::OLE from within a single thread of your program and carefully set it up there using ->Initialize (and the appropriate COINIT_ value). You should also only use objects retrieved within that thread in only that thread.

      COM+ dlls use the registry to indicate what threading model STA,MTA,Free etc they use, and if they are in-proc (dll) or out-of proc (exe).

      So better check the thread model first to see if it even can be accessed by multiple threads and if so then set your OLE initialization with the appropriate COINT_ value

      Normally even if the dll is not multi-thread aware it should pose no problem since it would serialize the calls through the STA, but there is so much going on behind the scene, especially COM+ objects being prone to re-entrancy issues,that make Corion's advise (use OLE from one thread) the one to follow

Re: Perl crashs always during global destruction when using WIN32 OLE object in multithread
by BrowserUk (Patriarch) on Mar 03, 2011 at 07:29 UTC

    How could your code possibly work when you attempt to create a Win32::OLE object, before you either use'd it or required it?

    The code you've posted obviously isn't the code you're running and which is producing the error messages. So why waste our time?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-16 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found