[lkml]   [2003]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Lockless file reading
Timo Sirainen wrote:
> checksum[0]++;
> xor = buf[0] ^ checksum[0];

Your algorithm isn't going to work if the new value of xor is the same
as the old value of xor.

> do {
> memcpy(copy, buf, size*2);
> } while (!verify(copy, size));
> memcpy(data, copy, size);

It isn't safe because the memcpy() can read writes done on another
processor out of order, and xor does not always change.

You can read some of the newly written bytes in both the buf[] and
checksum[] halves of the buffer, while reading some of the previous
bytes in each half. If the set of new bytes in the first half matches
the set in the second half well enough (i.e. the two sets match for
bytes which aredifferent between the old and new data blocks), and the
xor values are the same between the old and new data blocks, then your
test will accept a mix of old and new data bytes.

-- Jamie
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:48    [W:0.206 / U:0.616 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site