Problem with function ethr_rwmutex_tryrlock
JR Zhang
zhangjr2009@REDACTED
Wed May 26 22:36:45 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
More information about the erlang-bugs
mailing list