Open
Description
openedon Oct 15, 2024
unlock(rl::ReentrantLock) does a notify(cond) which wakes all tasks waiting on the lock. As this is a lock, only one of these tasks can succeed, so it is unnecessary to schedule all of them. When there are a large number of tasks, the current approach wastes CPU time and can cause a quadratic amount of allocations for waitlist nodes.
It isn't straightforward to trivially fix this by changing the notify
call to set all=false
-- unlock
will only call notify
if ReentrantLock.havelock
is 0x02
(see here) and that only happens after the first notify
if all waiting tasks are woken up to race for the lock again (see here).
Broken out from #50425 as this is a separate issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment