in reply to Re: Waitpid does not work as expected in Windows
in thread Waitpid does not work as expected in Windows

Thanks for your reply!
I did not know that pids in Windows were negative.

Also, your suggestion about removing
use Win32::OLE('in');
solved the problem. Unfortunately, I need this module because the code snippet I posted is part of a larger project that needs Win32::OLE->GetObject function. Do you know what causes this incompatibility? Is there a way in Perl to use a module for a part of the program and disable it for the rest rather than defining it in a global scope?

Thanks in advance
  • Comment on Re^2: Waitpid does not work as expected in Windows

Replies are listed 'Best First'.
Re^3: Waitpid does not work as expected in Windows
by ikegami (Patriarch) on Sep 29, 2008 at 11:50 UTC

    I did not know that pids in Windows were negative.

    They're not. That's why negative numbers were used to id the pseudo-processes created by fork.

    Do you know what causes this incompatibility?

    The usual possibilities:

    • A race condition. Not very likely here considering the simplicity of the code and the repeatability of the problem.
    • Something that should only be called once is being called once for each thread.
    • Something is called from one thread but expects to be called from another.

    On the Perl side, every variable gets copied when you create a new thread. That makes Perl code more-or-less thread-safe by default. But that's not the case on the C component of XS modules. C variables are shared among threads "by default".

    Workarounds:

    • If you only need Win32::OLE in the parent, you could try loading it after all threads have been created. This will probably entail using require instead of use.
    • If you only need Win32::OLE in the child, you could try loading it from the thread. This will probably entail using require instead of use.
    • If you need Win32::OLE in both the parent and the child, it probably won't work based on the evidence we've seen. Using separate processes would do the trick.
      Your suggestion to require the module instead of 'using' it did the work. Thanks a lot for all the useful info and help!
      Athanasia