Re: Locking scheme to block less

From: Rik van Riel
Date: Mon Aug 09 2004 - 20:40:55 EST


On Mon, 9 Aug 2004, John Richard Moser wrote:

> Currently, the kernel uses only spin_locks,

Oh ? Haven't you seen the read/write locks in
include/linux/spinlock.h or the lockless synchronisation
provided by include/linux/rcu.h ?

> If the kernel provided a read-write locking semaphore,

Funny, it does. You're not looking at a 2.0 kernel, are
you?

> spin_read_to_write_lock(spin_rwlock_t *lock);

> A read_to_write lock will block two such operations from occuring
> concurrently, while still allowing read only operations AND still being
> blocked when switched to write mode by both read and write operations.

In fact, two threads trying to upgrade their read lock to a
write lock simultaneously will block EACH OTHER, FOREVER.

Sounds like an exceedingly bad idea to me ;)

--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/