Skip to content

Commit 5ac9df0

Browse files
committed
Fix race condition in thread pool.
This was failing in JRuby, causing Travis to complain.
1 parent 227037e commit 5ac9df0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/rake/thread_pool.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,19 @@ def process_queue_item #:nodoc:
109109
false
110110
end
111111

112+
def safe_thread_count
113+
@threads_mon.synchronize do
114+
@threads.count
115+
end
116+
end
117+
112118
def start_thread # :nodoc:
113119
@threads_mon.synchronize do
114120
next unless @threads.count < @max_active_threads
115121

116122
t = Thread.new do
117123
begin
118-
while @threads.count <= @max_active_threads
124+
while safe_thread_count <= @max_active_threads
119125
break unless process_queue_item
120126
end
121127
ensure
@@ -126,6 +132,7 @@ def start_thread # :nodoc:
126132
end
127133
end
128134
end
135+
129136
@threads << t
130137
stat(
131138
:spawned,

0 commit comments

Comments
 (0)