Hi, On Saturday 01 April 2006 21:56, Jerry Feldman wrote:
The location pointer should be atomic. I did not run a recent stress test on the 2.6 kernel. One of the problems is that you used streamIO, where the buffering is both in user space and underneath in kernel space. The system calls, open(2), dup(2), write(2), close(2) are atomic. And as I mentioned, they refer to the same single kernel open file structure. But, the streamIO functions are library functions and are not guaranteed to be atomic.
[deleted]
Another way is to write your own function using the vsprintf(3) function. I know that using a fixed size buffer here is unsafe, but I'm using it for the example. In the function, below, by using write(2) you are bypassing the stream's file structure (and its own location pointer).
I tried out your suggestion to bypass C stdio. I purposely open a file using O_WRONLY|O_CREAT|O_TRUNC only (no O_APPEND or O_DIRECT), then do the write without locking. The result, I can still get the race condition where both processes write from the beginning of the file. Looks like use either O_APPEND or application-level handling to guarantee that the race condition won't happen. -- Regards, Verdi