in reply to Multithreaded script keeps files locked when reading output from multiple processes on Windows
They are open without the FILE_SHARE_DELETE permission.
This is true on all systems.
The reason you cannot delete file1 even after thread 1 has ended is because when the 3rd copy of Perl.exe is spawned in thread 2, that process inherits all open file handles, including that of file 1.
As another process has an open file handle without the FILE_SHARE_DELETE permission, the file cannot be deleted by the creating process until that other process terminates.
If you run this modified version of your test code, you'll see that the main thread can delete file 1 whilst thread 2 is still running; but only after the process thread 2 spawns, terminates.
The output:
C:\test\junk>..\junk41 26: Cant remove file1 because Permission denied/The process cannot acc +ess the file because it is being used by another process 29: Cant remove file2 because Permission denied/The process cannot acc +ess the file because it is being used by another process [1] eof pipe [1] pipe closed [1] thread ending 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process 32: Still cant remove file1 because Permission denied/The process cann +ot access the file because it is being used by another process [2] eof pipe [2] pipe closed [2] thread ending 36: This isnt printed No such file or directory/The system cannot find + the file specified
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multithreaded script keeps files locked when reading output from multiple processes on Windows
by rmahin (Scribe) on Jan 13, 2014 at 23:25 UTC | |
by BrowserUk (Patriarch) on Jan 14, 2014 at 09:49 UTC | |
by rmahin (Scribe) on Jan 14, 2014 at 20:40 UTC | |
by rmahin (Scribe) on Jan 13, 2014 at 23:29 UTC |