#5121
Yutaka Emura
Keymaster

Flint wrote:
Well, here are the results of the first part of my tests.
1. First of all, it is not Perl interpreter who drops the error. It is Bash. I started my PL-script by simple calling it via ./my_script.pl, and when I changed it into explicit call of perl (/usr/bin/perl ./my_script.pl) the error no longer appears. However, it does not solve anything. I tried also to look through the source code of Bash interpreter to find the conditions on which it drops this error, but there was no such error message…
2. I tried to reproduce the problem using Notepad instead of EmEditor – but failed. I tried to do it about 30-40 times, and no error appeared, while with EmEditor it appears after approximately every 4-5 openings.
3. I tried to write a program that runs on the virtual machine and constantly tries to open and close the file with read-write access, and while this program was running tried to open the file in EmEditor – and again, no problem appeared. :-(

So, all this seems as if EmEditor during opening a file set a very specific lock, which causes Bash (and only Bash) to fail opening the same file at the same moment. After EE read the file into memory, it releases the lock, but it’s too late – Bash already failed to open the file.

Moreover, I also tried to set the option “Changed by Another Program” to “Keep Locked” – and even then the file was correctly opened and executed by Bash+Perl! So, the lock while opening a file and the lock after it’s opened are two completely different locks.

I’ll be trying further…

I tried to reproduce your problem here, but I coldn’t. EmEditor works as it is supposed to.

I created a test program, which opens a test file with GENERIC_READ | GENERIC_WRITE access and FILE_SHARE_READ share every 100ms, and alerts if it fails to open a file.
I also created a macro which opens the same file within EmEditor every 9 ms. When both run, nothing happens until I stop them. If the test program opens the file without FILE_SHARE_READ share, then conflict appears.

The test program I used is C++:


for(;;){
HANDLE hFile = CreateFile( _T("E:testtest.txt"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL );
if( hFile == INVALID_HANDLE_VALUE ){
if( MessageBox( NULL, _T("CreateFile error."), NULL, MB_OKCANCEL ) != IDOK ){
return 1;
}
}
CloseHandle( hFile );
Sleep(100);
printf( _T(".") );
}

The macro I used for EmEditor is JavaScript for EmEditor:


editor.NewFile();
for( i = 0; i < 10000; i++ ){
document.write(".");
editor.OpenFile( "E:TestTest.txt", eeEncodingSystemDefault, eeOpenDetectUnicode | eeOpenAllowNewWindow );
document.close();
Sleep( 9 );
}