Subj : Re: what shall we do when a lock fails To : comp.programming.threads From : Joseph Seigh Date : Sun Jan 09 2005 07:56 am On Sun, 09 Jan 2005 01:36:40 -0700, Andy Yang wrote: > Hi, > > I am pretty new to pthread programming. Currently I am reading David's > Book, Programming with Posix Thread. In Chapter 7, page 261, David gives > out an example on read/write lock. The code is as follows: > > int rwl_readlock(rwlock_t *rwl) > { > ... > if (rwl->w_active){ > rwl->r_wait++; > pthread_cleanup_push(rwl_readcleanup, (void*)rwl); > while(rwl->w_active){ > status = pthread_cond_wait(&rwl->read, &rwl->mutex); > if (status != 0) break; > } > pthread_clean_pop(0); > rwl->r_wait--; > } > if (status == 0) rwl->r_active; > pthread_mutex_unlock(&rwl->mutex); > return status; > } > > This segment of code return erronous status code back to the user, > in case something goes wrong inside. Here my questions is, in this case, > how shall we deal with the error when we use this read/write lock, > or other similar locks that we build with pthreads routines? > Abort or throw an exception. The most likely causes are incorrect use or initialiation of the lock, or something clobbered the lock. There is no meaningful runtime recovery in either case. -- Joe Seigh .