Re: Read/write locks

Linus Torvalds (torvalds@transmeta.com)
Sun, 21 Sep 1997 04:16:55 -0700 (PDT)


On Sun, 21 Sep 1997, David S. Miller wrote:
>
> An update lock lets you read the structure while guaranteeing it
> will not change, and also that you can upgrade it to a write lock
> without the structure changing.
>
> Perhaps I'm feeling dense this evening, but what in the world is the
> difference then between holding the update lock and holding a rwlock
> as a writer? I can't see it...

While holding an update lock, others can still be reading, but no writers
(or other updaters) will be admitted.

Think of it as a way of saying "I want a read lock now, but I want a
guarantee that I can upgrade this read lock to a write lock later". You
can't do that with normal rw-locks, because if two processes both get a
read lock and both want to upgrade to a write lock, you have a deadlock.

That's why you have to tell about your intention to upgrade first (thus
the "update" lock: it's used for a read-modify-write cycle). Then the
locking mechanism can make sure you don't have two updaters at the same
time even if you have multiple readers.

Linus