From edc927709a47e5a605b1bdbba1c0d5ae41cfb8d4 Mon Sep 17 00:00:00 2001 From: Patrick Mahoney Date: Tue, 20 Dec 2011 22:12:25 -0600 Subject: [PATCH] Avoid possible race in ConditionVariable where new processes begin waiting while #broadcast is running. --- lib/process_shared/condition_variable.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/process_shared/condition_variable.rb b/lib/process_shared/condition_variable.rb index 4348d1d..3079aa6 100644 --- a/lib/process_shared/condition_variable.rb +++ b/lib/process_shared/condition_variable.rb @@ -10,7 +10,9 @@ module ProcessShared end def broadcast - waiting.times { @sem.post } + @internal.synchronize do + @waiting.read_int.times { @sem.post } + end end def signal @@ -38,12 +40,6 @@ module ProcessShared private - def waiting - @internal.synchronize do - @waiting.read_int - end - end - def inc_waiting(val = 1) @internal.synchronize do @waiting.write_int(@waiting.read_int + val)