Re: [PATCH] Upgradeable read locks for USB

Colin Plumb (colin@nyx.net)
Sun, 11 Jan 1998 19:05:34 -0700 (MST)


Inaky Perez Gonzalez wrote:
> I've found a simpler sollution which does what I need to
> do. It doesn't need to use any special kind of lock, just the normal
> ones. The code goes in, read locks, and then decides it has to
> write. It upgrades the read lock to write lock, writes, releases the
> write lock, and later (when due), releases the read lock.

> What it is done is, when requesting the upgrade, wait until
> there's only ONE reader holding the lock; this is our read lock, and
> we can easily set the write bit. Then we can unlock with
> write_unlock(), what will keep the read lock still held.

Aiee! Do NOT do this! Deadlock! Deadlock!

Consider what happens if two people with read locks try to upgrade
at the same time.

Each will wait for the read count to become 1, which it never will because
neither is releasing their read lock until they get a write lock.

This is the difference between an upgradeable read lock and a regular
non-upgradeable one: only one upgradeable read lock is allowed to exist
at a time.

-- 
	-Colin