public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/7057] New: pthread rwlock does not implement 'writer preferred' option
@ 2008-11-26 15:57 udig at il dot ibm dot com
  2008-11-26 16:11 ` [Bug nptl/7057] " drepper at redhat dot com
  2008-11-30 17:35 ` sjmunroe at us dot ibm dot com
  0 siblings, 2 replies; 4+ messages in thread
From: udig at il dot ibm dot com @ 2008-11-26 15:57 UTC (permalink / raw)
  To: glibc-bugs

When creating a rwlock, ask for PTHREAD_RWLOCK_PREFER_WRITER_NP.
The resulting behavior is identical to PTHREAD_RWLOCK_PREFER_READER_NP, as can
be seen in the source.
The following test case shows that as long as there are readers holding the
lock, a writer thread will be starved forever.
However, if the PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP option is used, the
writer thread gets to run. It is not allowed to be recursive, however.
-------------------------------------------------------------
#define _XOPEN_SOURCE 600
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <time.h>
#include <error.h>
#include <string.h>

#define NUM_THREADS (250)

pthread_rwlock_t lock;

void *readfunc(void *arg)
{
    long long id = (long long)arg;

    while (1) {
        struct timespec ts = {.tv_sec = 0,.tv_nsec = (id%25 +1)*1000*1000 };
 
        assert(0==pthread_rwlock_rdlock(&lock));
        nanosleep(&ts,NULL);
        assert(0==pthread_rwlock_unlock(&lock));
    }
}

void *writefunc(void *arg)
{   
    sleep(1);
    assert(0==pthread_rwlock_wrlock(&lock));
    //   assert(0==pthread_rwlock_wrlock(&lock)); //would fail if non-recursive
    printf("Writer got a chance!\n");
    //   assert(0==pthread_rwlock_unlock(&lock));
    assert(0==pthread_rwlock_unlock(&lock));
    
    return 0;
}

int main(int argc,char *argv[])
{
    pthread_t writer,readers[NUM_THREADS];
    pthread_rwlockattr_t lockattr;
    assert(0==pthread_rwlockattr_init(&lockattr));
   
assert(0==pthread_rwlockattr_setkind_np(&lockattr,PTHREAD_RWLOCK_PREFER_WRITER_NP));


    assert(0==pthread_rwlock_init(&lock,&lockattr));
    assert(0==pthread_rwlockattr_destroy(&lockattr));

    for (long long i=0;i<NUM_THREADS;i++)
        assert(0==pthread_create(readers+i,NULL,readfunc,(void *)i));
    assert(0==pthread_create(&writer,NULL,writefunc,0));
    
    printf("main waits\n");
    pthread_join(writer,NULL);
    return 0;
}

-- 
           Summary: pthread rwlock does not implement 'writer preferred'
                    option
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: udig at il dot ibm dot com
                CC: glibc-bugs at sources dot redhat dot com


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

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug nptl/7057] pthread rwlock does not implement 'writer preferred' option
  2008-11-26 15:57 [Bug nptl/7057] New: pthread rwlock does not implement 'writer preferred' option udig at il dot ibm dot com
@ 2008-11-26 16:11 ` drepper at redhat dot com
  2008-11-30 17:35 ` sjmunroe at us dot ibm dot com
  1 sibling, 0 replies; 4+ messages in thread
From: drepper at redhat dot com @ 2008-11-26 16:11 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2008-11-26 16:10 -------
And there won't be any implementation.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


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

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug nptl/7057] pthread rwlock does not implement 'writer preferred' option
  2008-11-26 15:57 [Bug nptl/7057] New: pthread rwlock does not implement 'writer preferred' option udig at il dot ibm dot com
  2008-11-26 16:11 ` [Bug nptl/7057] " drepper at redhat dot com
@ 2008-11-30 17:35 ` sjmunroe at us dot ibm dot com
  1 sibling, 0 replies; 4+ messages in thread
From: sjmunroe at us dot ibm dot com @ 2008-11-30 17:35 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From sjmunroe at us dot ibm dot com  2008-11-30 17:33 -------
Uli I think this question deserves a more complete explanation. 

This seems like a reasonable request. If you disagree then it would not hurt 
to explain why.

There seems to be a valid concern related to reliable implementation of 
recursive read locks with writer priority. As in this discusion:

http://sources.redhat.com/ml/libc-alpha/2000-01/msg00055.html

If this your concern then saying so would help resolve/close this issue.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bmark at us dot ibm dot com


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

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug nptl/7057] pthread rwlock does not implement 'writer preferred' option
       [not found] <bug-7057-131@http.sourceware.org/bugzilla/>
@ 2014-07-01 21:11 ` fweimer at redhat dot com
  0 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2014-07-01 21:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=7057

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-01 21:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-26 15:57 [Bug nptl/7057] New: pthread rwlock does not implement 'writer preferred' option udig at il dot ibm dot com
2008-11-26 16:11 ` [Bug nptl/7057] " drepper at redhat dot com
2008-11-30 17:35 ` sjmunroe at us dot ibm dot com
     [not found] <bug-7057-131@http.sourceware.org/bugzilla/>
2014-07-01 21:11 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).