adding noreturn attribute to pthread_exit

2013-01-14 Thread Antti Kantee

Hi,

Calling pthread_exit() at the end of a routine marked noreturn produces 
a compiler warning/error on cygwin:


error: 'noreturn' function does return

Is it possible to add the attribute to the cygwin pthread.h:

--- pthread.h.orig  2012-10-19 14:40:13.0 +0200
+++ pthread.h   2013-01-14 21:40:00.018198900 +0100
@@ -137,7 +137,7 @@
void *(*)(void *), void *);
 int pthread_detach (pthread_t);
 int pthread_equal (pthread_t, pthread_t);
-void pthread_exit (void *);
+void pthread_exit (void *) __attribute__((__noreturn__));
 int pthread_getcpuclockid (pthread_t, clockid_t *);
 int pthread_getschedparam (pthread_t, int *, struct sched_param *);
 void *pthread_getspecific (pthread_key_t);

(note, i didn't check how it needs to trickle down in the cygwin 
implementation of pthread_exit())


  - antti

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



pthread_rwlock_tryrdlock bug (with test patch)

2013-01-06 Thread Antti Kantee
[I'd submit this to cygwin-patches, but the web page says only 
subscribers can post to that list, so please bear with me for this 
simple issue]


Hi,

Calling pthread_rwlock_tryrdlock() twice from the same thread always 
fails with EBUSY the second time.  See attached test.c.  Replacing the 
second tryrdlock() with rdlock() makes the call succeed, leading me to 
believe there is a bug in tryrdlock().


Assuming I was looking at the correct source file, the attached patch 
should fix the issue.  I'm not sure why the lookup_reader() call was 
there in the first place; perhaps a remnant from a time when recursive 
read locking was not supported?


While looking at tryrdlock(), the handling of ULONG_MAX also seems 
wrong, as you'd probably want to return EAGAIN instead of allocating 
another reader structure.  However, that problem is arguably more of an 
academic issue and therefore I didn't touch it in my patch.


  - antti

p.s. please cc me on any responses
#include err.h
#include pthread.h
#include stdio.h

int
main()
{
pthread_rwlock_t lck;
int rv;

pthread_rwlock_init(lck, NULL);
if ((rv = pthread_rwlock_tryrdlock(lck)) != 0)
errx(1, lock 1: %d, rv);
if ((rv = pthread_rwlock_tryrdlock(lck)) != 0)
errx(1, lock 2: %d, rv);
printf(success\n);
}
--- src/winsup/cygwin/thread.cc.old 2012-08-17 01:34:45.0 +0200
+++ src/winsup/cygwin/thread.cc 2013-01-06 17:58:46.258963200 +0100
@@ -1427,7 +1427,7 @@ pthread_rwlock::tryrdlock ()
 
   mtx.lock ();
 
-  if (writer || waiting_writers || lookup_reader (self))
+  if (writer || waiting_writers)
 result = EBUSY;
   else
 {

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple