On Tuesday 26 April 2005 11:55, Gaurav Dhiman wrote: > why we need to keep a count of readers, does that matter ? You need to know when the number of readers is 0 so a writer can get the lock. If you don't keep that count, how to you tell at any one time if there are still any readers? Without a count something like this would happen. - reader_a see the lock is not held and issues a read lock. - reader_b see a read lock already held and proceeds to access the data. - reader_a releases the lock - writer_c see the lock not held and modifies the data but reader_b is still accessing the data. With the count - reader_a sees the lock is not held and increments the reader count - reader_b increments the reader count - reader_a decrements the reader count - writer_c sees one or more readers have a lock and spins. - reader_b decrements the reader count thus freeing the lock - writer_c can now grab a write lock. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/