You are not logged in.
Pages: 1
Hi Arnaud,
I got an error message something like "Cannot open myProgram.mab file, another program is using it" in my program, where multiple threads has their own TSynLog objects.
My derived TEyLog:
constructor TEyLogger.Create(const aLogFilePath: string; const aBufSize:
Integer = 4096);
begin
FSpecifiedLogFile := aLogFilePath;
FSpecifiedBufferSize := aBufSize;
inherited Create(nil);
//by default accept all levels of logging
Self.Family.Level := LOG_VERBOSE;
Self.GenericFamily.Level := LOG_VERBOSE;
end;
procedure TEyLogger.CreateLogWriter;
begin
if fWriterStream = nil then
begin
fFileName := FSpecifiedLogFile;
if not FileExists(fFileName) then
TFileStream.Create(fFileName, fmCreate).Free; // create a void file
fWriterStream := TFileStream.Create(fFileName, // open it with read sharing
fmOpenReadWrite or fmShareDenyWrite);
end;
if fWriter = nil then
begin
if FSpecifiedBufferSize < 64 then
FSpecifiedBufferSize := fFamily.BufferSize;
fWriter := SynCommons.TTextWriter.Create(fWriterStream, FSpecifiedBufferSize);
end;
end;
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
done: http://synopse.info/fossil/tktview/ea4e … 3d017e997f
What would be the idea of fixing it?
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Just let the .Mab file be opened by multiple threads at once.
Update:
It is weird, .mab file opening is already tread-safe.
It is opened with:
constructor TSynMemoryStreamMapped.Create(const aFileName: TFileName; aCustomSize: cardinal; aCustomOffset: Int64);
begin
fFileStream := TFileStream.Create(aFileName,fmOpenRead or fmShareDenyNone);
My only option may be to put a critical section within TSynMapFile.Create() but it sounds weird...
Offline
Thanks Arnaud, the problem's fixed. I guess fmShareDenyNone doesn't ensure thread-safety, I guess the problem was that, Thread B trying to open the same .mab file while thread A hasn't done its opening of the very same file.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Arnaud, you are welcome! You have done a great work!
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
It's not a subject of this topic, but another potential issue (from my POV) is in TMemoryMap.Map (called by TSynMemoryStreamMapped).
If file is 0 length TMemoryMap.Map return false and I got the exception. I fix this behavior many time in my code (not map file related), but may be it must be fixed in the synCommons just replace
if (fFileSize<=0) or (fFileSize>maxInt) then
with
if (fFileSize<0) or (fFileSize>maxInt) then
in TMemoryMap.Map?
UPD. UPS - CreateFileMapping(...) fail in this case....
Last edited by mpv (2014-07-17 15:34:37)
Offline
Offline
Pages: 1