tags:

views:

40

answers:

2

I have an application running on Linux, and I find myself wanting windows (!).

The problem is that every 1000 times or so I run into concurrency problems that are consistent with concurrent reading/writing of files. I am fairly sure that this behavior would be prohibited by file locking under Windows, but I don't have any sufficiently fast windows box to check.

There is simply too much file access (too much data) to expect strace to work reliably - the sheer volume of output is likely to change the problem too. It also happens on different files every time. Ideally I would like to change/reconfigure the linux file system to be more restrictive (as in fail-fast) wrt concurrent access.

Are there any tools/settings I can use to achieve this ?

+2  A: 

Hmmm. Concurrent access to files is perfectly legitimate on Posix-like systems so there is no kind of "failure" mode associated with it. Is there a reason you can't use file-locking on Linux? It's difficult to tell from your description what the actual problem is (1000 times of what?) but it sounds like the traditional flock() or lockf() system calls might be what you're looking for.

Rakis
Yes, if you control all the code potentially accessing the files, then you can use the advisory locks.
caf
+1  A: 

For some reason I thought you were using C++. The following applies if you are.

If you are using multi-threading and fstream IO and custom streambufs or you disabled sync_with_stdio, then yes, the C++ iostreams will act differently from iostreams on Windows.

I ran into this with one of my own projects.

Windows defines a mutex in its iostream sentry. Linux does not. Linux does seem to have locking in its C stdio functions, so usually that works out anyway.

However, I defined a custom debug streambuf that didn't go through stdio and got all sorts of corruption in Linux.

I got around it by using a mutex that is preprocessed out if the OS is Windows.

Zan Lynx
Ther's a multitude of languages involved, and alot of processes. Nice answer, it gives me a lot of interesting keywords for google. I'm actually thinking that buying a windows box just to track my problems would be solution, since the more aggressive file locking will probably catch my problem.
krosenvold