in reply to Re: Re: Starting multi-threading
in thread Starting multi-threading

Sorry! Bad guess. I did warn you I hadn't tried it.

Unfortunately, whilst the scripting object itself and OLE are reentrent, the means of getting to them from perl is not. Any attempt I make to use Win32::OLE from two threads at the same time, even if it is to two different OLE objects, the second one fails.

I took a quick scan at Win32::OLE but it doesn't look like it would be an easy thing to fix. It was written before threads were around, so reentrancy was never a consideration.

I had thought that by creating new instances in each thread, which under win32 is pretty much the same as creating different instances in seperate (pseudo-) processes, that it would isolate everything, but it would appear not.

As I said in the last post, I'm not sure how much you would have gained by threading for this anyway, but unless Win32::OLE gets an update some time soon, I don't see this being easily fixed.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.

Replies are listed 'Best First'.
Re: Re: Re: Re: Starting multi-threading
by blackadder (Hermit) on Aug 24, 2003 at 20:41 UTC
    Yep, I realise this now, and thanks.

    I was intending to stat more than one shared area on remote server, so my @ARGV parameters would've been something like \\uk_server01\d$\shared_area1, rather than my local hard disk, apologies I should've been more specific here.

    Ok, I am abandoning mission. Thanks again for saving me the hassle:-).

      It might be worth trying liz's forks.pm.

      Still no guarentees, but as your drives are remote drives, with seperate spindles and network latency, there is not doubt that your application would benefit from multi tasking.

      It is a shame that Win32::OLE isn't reentrant. Were it, then your application would be an idea application for threading.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
      If I understand your problem, I can solve it! Of course, the same can be said for you.

        The most important thing to get standard modules thread-safe, is to look at the CLONE {} dummy sub. This is called before the thread is cloned. However, this still takes place inside the environment of the original thread, which may not always what you want. Which was one of the reasons for creating Thread::Exit.

        So if there is some cloning to do to get thread-safe, first try to get it done with CLONE {}, if that fails try with Thread::Exit.

        Yet another approach could be to load Win32::OLE inside each thread. You can either require inside the thread, or use (you guessed it): Thread::Use, which allows you to say:

        useit Win32::OLE;
        where useit stands for "use inside thread".

        Hope this helps someone looking at making Win32::OLE thread-safe.

        Liz