|
From: | Paolo Bonzini |
Subject: | Re: [RFC PATCH 4/4] coroutine/rwlock: Wake writers in preference to readers |
Date: | Tue, 9 Mar 2021 12:06:22 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 |
On 09/03/21 11:21, David Edmondson wrote:
- /* The critical section started in qemu_co_rwlock_wrlock. */ - qemu_co_queue_restart_all(&lock->queue); + /* The critical section started in qemu_co_rwlock_wrlock or + * qemu_co_rwlock_upgrade. + */ + qemu_co_queue_restart_all(&lock->wqueue); + qemu_co_queue_restart_all(&lock->rqueue);
Hmm, the devil is in the details---this is a thundering herd waiting to happen. But fortunately this can be fixed while making the unlock primitive even simpler:
if (lock->reader) { self->locks_held--; /* Read-side critical sections do not keep lock->mutex. */ qemu_co_mutex_lock(&lock->mutex); lock->reader--; assert(lock->reader >= 0); } /* If there are no remaining readers wake one waiting writer * or all waiting readers. */ if (!lock->reader && !qemu_co_queue_next(&lock->wqueue)) { assert(!lock->pending_writer); qemu_co_queue_restart_all(&lock->rqueue); } Thanks, Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |