LWN.net Logo

Fast reader/writer locks

Fast reader/writer locks

Posted Jan 30, 2003 4:59 UTC (Thu) by rickfdd (guest, #4519)
Parent article: Fast reader/writer locks

Can't the pre and post sequence numbers can be combined
to one memory location using odd and even values instead? It
would enable earlier failed read detection, which can spin or
yield as appropriate, although the branch cost is usually
more than the critical section anyway.


(Log in to post comments)

Fast reader/writer locks

Posted Jan 30, 2003 5:16 UTC (Thu) by cpeterso (guest, #305) [Link]

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.

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