in reply to Re^2: Multithreaded script keeps files locked when reading output from multiple processes on Windows
in thread Multithreaded script keeps files locked when reading output from multiple processes on Windows

process A will still have a filehandle for file1 even though thread2 did absolutely nothing with the file because the spawned process inherits ALL of the the file handles currently in use by the main perl process at the time of opening the pipe?

That is correct, but overstates the conditions.

Forget which thread does what. Indeed, forget threads entirely. (Even forget the file bit.)

When one process spawns another process, the child process will inherit every open handle that has the bInheritHandle flag set in the Security Attributes structure supplied when that handle was created in the parent.

At the Win32 API level, this can be controlled on a per (file) handle basis; but as POSIX doesn't have that concept, Perl doesn't provide access to it and thus uses a generic security descriptor that means everything gets inherited.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.
  • Comment on Re^3: Multithreaded script keeps files locked when reading output from multiple processes on Windows

Replies are listed 'Best First'.
Re^4: Multithreaded script keeps files locked when reading output from multiple processes on Windows
by rmahin (Scribe) on Jan 14, 2014 at 20:40 UTC

    That was all very illuminating! Thanks a bunch for your time and explanation. :)