It is a reader-writer consistent mechanism which
avoids the problem of writer starvation.
The reader never blocks, but it may have to retry
if a write is in progress; this speeds up the readers
in the case where the data was not modified, since they
do not have to acquire the lock as they would with a
traditional read-write lock. Also, writers do not wait
for readers, whereas with traditional read-write locks
they do, leading to potential resource starvation in a
situation where there are a number of readers (because
the writer must wait for there to be no readers).
Because of these two factors, seqlocks are more efficient than
traditional read-write locks for the situation where there are
many readers and few writers. The drawback is that if there is
too much write activity or the reader is too slow, they might
livelock (and the readers may starve).
int readcount, writecount; (initial value = 0)
semaphore mutex 1, mutex 2, mutex 3, w, r ; (initial value = 1)
READER
P(mutex 3);
P(r);
P(mutex 1);
readcount := readcount + 1;
if readcount = 1 then P(w);
V(mutex 1);
V(r);
V(mutex 3);
reading is done
P(mutex 1);
readcount := readcount - 1;
if readcount = 0 then V(w);
V(mutex 1);
WRITER
P(mutex 2);
writecount := writecount + 1;
if writecount = 1 then P(r);
V(mutex 2);
P(w);
writing is performed
V(w);
P(mutex 2);
writecount := writecount - 1;
if writecount = 0 then V(r);
V(mutex 2);reference:http://en.wikipedia.org/wiki/Readers-writer_lock