Skip to content

Address FileThreadPool race condition #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/cc/engine/analyzers/file_thread_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def initialize(files, concurrency: DEFAULT_CONCURRENCY)

def run(&block)
queue = build_queue
lock = Mutex.new

@workers = thread_count.times.map do
Thread.new do
while !queue.empty? && (item = queue.pop(true))
while (item = next_item(queue, lock))
yield item
end
end
Expand All @@ -32,6 +33,10 @@ def join

attr_reader :files, :concurrency, :workers

def next_item(queue, lock)
lock.synchronize { queue.pop(true) unless queue.empty? }
end

def build_queue
Queue.new.tap do |queue|
files.each do |file|
Expand Down