LWN.net Logo

Fast reader/writer locks

Fast reader/writer locks

Posted Jan 30, 2003 5:16 UTC (Thu) by cpeterso (guest, #305)
In reply to: Fast reader/writer locks by rickfdd
Parent article: Fast reader/writer locks

I think there would be a race condition if the reader just looked for even/odd sequence number changes. If the sequence number was increments TWICE (by one or multiple writers), then the reader might not recognize the data change event.


(Log in to post comments)

Fast reader/writer locks

Posted Jan 30, 2003 13:43 UTC (Thu) by bastiaan (guest, #5170) [Link]

I guess what Rick means is that if you use one sequence the reader will know a concurrent write is in progress if the sequence is odd, in which case it can retry without first copying the data. In code:

do {
   while((seq = fr_read_seq(&some_lock)) & 1);
   /* copy data */
} while (seq != fr_read_seq(&some_lock));

However, since the concurrent write is very unlikely to happen, this extra test may be not worthwhile. But I still don't see why Stephen uses two sequences instead of one.

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