Problem with function ethr_rwmutex_tryrlock

Rickard Green rickard@REDACTED
Thu May 27 15:37:10 CEST 2010


> Hi list,
> 
> I think the fallback version of function ethr_rwmutex_tryrlock in
> erts/lib_src/common/ethread.c is not correct. This function should be
> similar with pthread_rwlock_tryrdlock. For pthread_rwlock_tryrdlock, the
> calling thread acquires the read lock if a writer does not hold the lock and
> there are no writers blocked on the lock. But as following code shows,
> ethr_rwmutex_tryrlock doesn't get the lock when there is no waiting writer,
> and acquires the lock when there are waiting writers. Am I right?
> 
>  ethr_rwmutex_tryrlock(ethr_rwmutex *rwmtx)
> {
>     int res;
> #if ETHR_XCHK
>     if (!rwmtx || rwmtx->initialized != ETHR_RWMUTEX_INITIALIZED) {
> ASSERT(0);
> return EINVAL;
>     }
> #endif
>     res = ethr_mutex_trylock__(&rwmtx->mtx);
>     if (res != 0)
> return res;
>     if (!rwmtx->waiting_writers) {
> res = ethr_mutex_unlock__(&rwmtx->mtx);
> if (res == 0)
>     return EBUSY;
> return res;
>     }
>     rwmtx->readers++;
>     return ethr_mutex_unlock__(&rwmtx->mtx);
> }
> 
> Best Regards,
> Jianrong Zhang
> 

Yes, you are right.

      if (!rwmtx->waiting_writers) {

should be

      if (rwmtx->waiting_writers) {

Thanks! It will be fixed in the upcomming release.

Regards,
Rickard

-- 
Rickard Green, Erlang/OTP, Ericsson AB.


More information about the erlang-bugs mailing list