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

Apparently Win32::OLE is not thread-safe or am I missing something? The curious thing is that all I am doing is pulling it in, if I comment out the "use Win32::OLE" statement everything is fine. It is somewhat disconcerting that a module that instantiates COM is having a problem w/ this. I am using ActiveState perl 5.8.0 build 805
#!/usr/bin/perl -w use 5.008; use threads; use strict; use Win32::OLE; my $thr = threads->new(\&sub1); my @data = $thr->join(); sub sub1 { print "INFO: In sub\n"; return "Fifty-six", "foo", 2; }
This produces the following:
"Free to wrong pool 15dcf98 not 15d24f8 during global destruction"

--ERick

Replies are listed 'Best First'.
Re: threading and Win32::OLE
by jand (Friar) on Mar 11, 2003 at 20:44 UTC

    No, you aren't missing anything. Win32::OLE is not compatible with the Perl 5.8 threading model.

    There are several issues that need to be solved:

    Whenever Perl creates a new thread, Win32::OLE needs to be informed of this so that it can initialize the COM subsystem for that thread (via CoInitializeEx()).

    Win32::OLE cannot simply be cloned and used in a different thread: COM objects belong to an "apartment", and depending on the COM threading model used by Perl and the external components, it is possible that COM pointers need to be marshalled to be accessible from a different thread.

    It is on my todo list to implement this, but I'm currently very busy with other stuff.

    BTW, there are other modules too that need per-thread initialization etc. that need fixing before they can be used with Perl 5.8 and threads, e.g. Win32::ODBC.

      thanks for the explanation and the heads up. Hope you become less busy with other stuff in the near future ;)

      --ERick