Date: Mon, 5 Jan 2004 14:30:14 -0800 (PST) From: Earl Chew <earl_chew@agilent.com> To: freebsd-threads@FreeBSD.org Subject: Re: misc/24641: pthread_rwlock_rdlock can deadlock Message-ID: <200401052230.i05MUEov039020@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/24641; it has been noted by GNATS. From: Earl Chew <earl_chew@agilent.com> To: aspiesrule@mcleodusa.net Cc: freebsd-gnats-submit@freebsd.org Subject: Re: misc/24641: pthread_rwlock_rdlock can deadlock Date: Mon, 05 Jan 2004 14:21:00 -0800 aspiesrule@mcleodusa.net wrote: > Same results, except for the fact that stepping thru your code in GDB yields > a segfault in KERNEL32!IsBadWritePtr. It must be the holidays! Ok, I've added the missing line at the beginning of wrfunc(). Earl -- #include <pthread.h> #include <stdio.h> #include <unistd.h> #include <assert.h> static pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER; static volatile int wrStarted; void * wrfunc(void *unused) { wrStarted = 1; printf("Attempt to acquire write lock\n"); assert(pthread_rwlock_wrlock(&rwlock1) == 0); printf("Acquired write lock\n"); assert(pthread_rwlock_unlock(&rwlock1) == 0); return 0; } static volatile int rdStarted; void * rdfunc(void *unused) { printf("Attempt to acquire read lock first\n"); assert(pthread_rwlock_rdlock(&rwlock1) == 0); printf("Acquired read lock first\n"); rdStarted = 1; while (wrStarted == 0) sleep(1); printf("Attempt to acquire read lock second\n"); assert(pthread_rwlock_rdlock(&rwlock1) == 0); printf("Acquired read lock second\n"); assert(pthread_rwlock_unlock(&rwlock1) == 0); assert(pthread_rwlock_unlock(&rwlock1) == 0); return 0; } int main(int argc, char **argv) { pthread_t wrt; pthread_t rdt; pthread_attr_t a; assert(pthread_rwlock_init(&rwlock1, 0) == 0); assert(pthread_attr_init(&a) == 0); assert(pthread_create(&rdt, &a, rdfunc, NULL) == 0); while (rdStarted == 0) sleep(1); assert(pthread_create(&wrt, &a, wrfunc, NULL) == 0); assert(pthread_join(wrt, 0) == 0); assert(pthread_join(rdt, 0) == 0); assert(pthread_rwlock_destroy(&rwlock1) == 0); assert(pthread_detach(wrt) == 0); assert(pthread_detach(rdt) == 0); return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401052230.i05MUEov039020>