|
|
| Author |
Message |
|
| Guest |
Posted: Wed May 26, 2010 8:37 pm |
|
|
|
Guest
|
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
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu May 27, 2010 1:39 pm |
|
|
|
Guest
|
> 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:erlang-bugs-unsubscribe@erlang.org
Post received from mailinglist |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|