read-write lock is defined as follws in kernel: File: linux/include/asm-i386/spinlock.h typedef struct { volatile unsigned int lock; #if SPINLOCK_DEBUG unsigned magic; #endif } rwlock_t; If we look at the rwlock_t structure shown above (which is actually the read write lock), it is same as spinlock with only one lock element (lock). Now, my question is, as there is only one lock element in the structure, how can a second or third reader come to know if the lock has been acquired by a reader or by a writer. If the lock has been acquired by reader, then this second or third reader should be allowed to enter c-region, else if it has already been acquired by writer, this reader should not be allowed to enter, but how we will come to know who actually acquired the lock (was that a reader or writer). I think there should be two lock elemets in the read-write spinlocks to differentiate between the concept of read lock and write lock. Correct me whereever I am wrong. -gd On 4/26/05, Thomas Petazzoni <thomas.petazzoni@xxxxxxxx> wrote: > Hello, > > Gaurav Dhiman wrote: > > > I think if we allows the writer to be in critical section, no one else > > (not even readers) should be allowed there in critical section, > > because writer may effect what the reader are reading and a situation > > like above (if I am correct) can lead to crashes. > > What the document says is : at a given time, you can have many readers > in the critical section OR one writer in the critical section. So you're > right, read/write locks can be taken by many readers at the same time OR > by only ONE writer at a time if there aren't any readers. > > Sincerly, > > Thomas > -- > Thomas Petazzoni > thomas.petazzoni@xxxxxxxx > -- -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/