Problem with function ethr_rwmutex_tryrlock

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problem with function ethr_rwmutex_tryrlock

Rickard Green-2
> 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.

________________________________________________________________
erlang-bugs (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]