Project

General

Profile

Actions

Feature #19717

open

`ConditionVariable#signal` is not fair when the wakeup is consistently spurious.

Added by ioquatix (Samuel Williams) over 1 year ago. Updated 11 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:113788]

Description

For background, see this issue https://github.com/socketry/async/issues/99.

It looks like ConditionVariable#signal is not fair, if the calling thread immediately reacquires the resource.

I've given a detailed reproduction here as it's non-trivial: https://github.com/ioquatix/ruby-condition-variable-timeout.

Because the spurious wakeup occurs, the thread is pushed to the back of the waitq, which means any other waiting thread will acquire the resource, and that thread will perpetually be at the back of the queue.

I believe the solution is to change ConditionVarialbe#signal should only remove the thread from the waitq if it's possible to acquire the lock. Otherwise it should be left in place, so that the order is retained, this should result in fair scheduling.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like1Like0Like0Like0Like0Like0Like0Like0Like0Like0