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

JR Zhang
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 (!rwmtx || rwmtx->initialized != ETHR_RWMUTEX_INITIALIZED) {
return EINVAL;
    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;
    return ethr_mutex_unlock__(&rwmtx->mtx);

Best Regards,
Jianrong Zhang