Skip to content

Commit

Permalink
Send wakeup signal to thread only if not dead
Browse files Browse the repository at this point in the history
The thread can report it is still running even though it will be
sleeping very soon.
  • Loading branch information
seven1m committed Dec 1, 2024
1 parent 17af0dd commit 6c01a3b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/thread/conditionvariable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ def initialize

def broadcast
@mutex.synchronize do
while !@waiting.empty?
until @waiting.empty?
thread = @waiting.shift
thread.wakeup if thread&.status == 'sleep'
if thread.status != 'dead'
thread.wakeup
end
end
end
end
Expand All @@ -21,10 +23,13 @@ def marshal_dump
def signal
@mutex.synchronize do
thread = nil
while !@waiting.empty? && thread&.status != 'sleep'
until @waiting.empty?
thread = @waiting.shift
if thread.status != 'dead'
thread.wakeup
break
end
end
thread&.wakeup
end
end

Expand Down

0 comments on commit 6c01a3b

Please sign in to comment.