LWN.net Logo

Fast reader/writer locks

Fast reader/writer locks

Posted Feb 2, 2003 8:24 UTC (Sun) by acristianb (guest, #1702)
Parent article: Fast reader/writer locks

If the writer starts by increasing the first seq then, the reader reads the first seq, reads data, then the writer changes data and second seq, than the reader reads the last seq, the two sequences match for the reader but the data is invalid.

A small twist of the reader algorithm that will solve this, and would make this frlock suitable for long (or longer) calculations is this:

* reads first seq and second seq
* compares them (if they are not equal start over because a writer is changing data)
* reads data
* reads second seq
* compares first and second sequences (if they are not equal start over)


(Log in to post comments)

Fast reader/writer locks

Posted Feb 6, 2003 4:37 UTC (Thu) by dneto (guest, #4954) [Link]

You've got the reader's seq ordering backward.
The writer updates seq pre, then seq post.
The reader checks seq post, then seq pre.
I think that avoids the problem you mention.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds