This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/10180] New: Write locks shall take precedence over read locks by default


I tested the scheduler of rwlock, and found that when write lock is blocked
(a read process has acquired read lock), the other read process can acquired
read lock again.

A read process                       <--acquired read lock
  ->A write process                  <--block for the reading process unlock
    ->The other read process         <--it acquired read lock again
      ->The write process            <--block for the two reading process unlock

If an application has many read process, the write process may be blocked at 
all 
times.

In pthread_rwlock_rdlock() manual, the other read process should be blocked 
when 
a write process blocked. Write locks shall take precedence over read locks by
default.

Signed-off-by: Zhang Xiliang <zhangxiliang@cn.fujitsu.com>
---
 nptl/pthread_rwlock_init.c     |    2 +-
 nptl/sysdeps/pthread/pthread.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/nptl/pthread_rwlock_init.c b/nptl/pthread_rwlock_init.c
index 27f25ac..7bc723b 100644
--- a/nptl/pthread_rwlock_init.c
+++ b/nptl/pthread_rwlock_init.c
@@ -46,7 +46,7 @@ __pthread_rwlock_init (rwlock, attr)
   rwlock->__data.__writer = 0;
 
   rwlock->__data.__flags
-    = iattr->lockkind == PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP;
+    = iattr->lockkind != PTHREAD_RWLOCK_PREFER_READER_NP;
 
   /* The __SHARED field is computed to minimize the work that needs to
      be done while handling the futex.  There are two inputs: the
diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
index cc7472e..91ab49c 100644
--- a/nptl/sysdeps/pthread/pthread.h
+++ b/nptl/sysdeps/pthread/pthread.h
@@ -117,7 +117,7 @@ enum
   PTHREAD_RWLOCK_PREFER_READER_NP,
   PTHREAD_RWLOCK_PREFER_WRITER_NP,
   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
-  PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
+  PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_WRITER_NP
 };
 
 /* Read-write lock initializers.  */

-- 
           Summary: Write locks shall take precedence over read locks by
                    default
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: zhangxiliang at cn dot fujitsu dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=10180

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]