Messages in this thread | | | Date | Thu, 28 Aug 2003 02:50:27 +0100 | From | Jamie Lokier <> | Subject | Re: 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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |