Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Aug : File locks on multiprocessor systems

www.cryer.info
Managed Newsgroup Archive

File locks on multiprocessor systems

Subject:File locks on multiprocessor systems
Posted by:"Marcus Mönnig" (usenet-apr..@40tude.com)
Date:Mon, 22 Aug 2005 10:52:41 +0200

Hi!

I am seeing a problem on multiprocessor systems only and would appreciate
some hints what could cause the problem, even if this is kind of long and
specific.

I am having some data in a file on disk that is loaded into memory. The file
is opened, loaded into memory and then closed. The data in memory gets
modified, so from time to time I want to flush this data from memory to
disk, so the file is recreated, saved to disk and closed. This flushing is
done in its own thread and both the loading and the saving are protected by
a global critical section and there is another protection that makes sure
that there is always only one flushing thread.
The flushing may occur as often as every 2 seconds. Never more frequently
and usually much less frequently, but it may happen every 2 seconds.

This concept works fine on single processor machines, but on dual processor
machines users randomly see EFCreateError  exceptions ("Cannot create file
.... The process cannot access the file because it is being used by another
process.").
I use madexcept so I have stack traces for all my running threads at that
time and there's usually just this flushing thread running and the main
thread that is idling. From these traces and from the code itself I am very
sure that this is not a threading problem on my side and that I am not
trying to access the same file twice or didn't close/free the filestream in
a previous flush.

At first, I thought there might be a virus scanner accessing the file at
that time, but this should happen on single processors systems, too, but it
never does.

So, my question is, are there any known pitfalls on multiprocessor system
regarding file access and locking?

My idea was that maybe if the flushing thread is run on processor 1 and just
2 seconds later the thread is run again on processor 2, even if I correctly
freed the stream the first time, Windows might still hold a lock on the file
and not yet give access to another processor and the error message should
really read "...used by another processor." Could this be the case?

Any other ideas what might be going on here?

Thanks a lot!
Marcus

Info

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive