Re: VFS locking: f_pos thread-safe ?

From: Joel Becker
Date: Fri Feb 06 2004 - 13:44:23 EST


On Fri, Feb 06, 2004 at 04:12:24AM -0300, Werner Almesberger wrote:
> Section 2.9.7 of the "Austin" draft of IEEE Std. 1003.1-200x,
> 28-JUL-2000, says:
>
> "[...] read( ) [...] shall be atomic with respect to each other
> in the effects specified in IEEE Std. 1003.1-200x when they
> operate on regular files. If two threads each call one of these
> functions, each call shall either see all of the specified
> effects of the other call, or none of them."

This reads: "all of the specified effects of the other call,
or none of them." If I read that correctly, if f_pos is at N, and
threads A and B concurrently read M bytes, then each thread's read()
must either start at f_pos = N or f_pos = N+M, but never at N < f_pos <
N+M. So as long as our code doesn't partially update f_pos, it is
valid.
Of course, that doesn't change the possible race updating
f_pos at the end of each thread's call.

Joel

--

"In a crisis, don't hide behind anything or anybody. They're going
to find you anyway."
- Paul "Bear" Bryant

Joel Becker
Senior Member of Technical Staff
Oracle Corporation
E-mail: joel.becker@xxxxxxxxxx
Phone: (650) 506-8127
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/