Sha256: 291696a205850b95d56c3f336e4940c6817e3edd3fb0a09487fa1e4aa33eadb2
Contents?: true
Size: 866 Bytes
Versions: 42
Compression:
Stored size: 866 Bytes
Contents
require 'common/ext/stdout' require 'stringio' require 'thread' module Bake module Multithread class Jobs def initialize(jobs, &block) nr_of_threads = [Bake.options.threads, jobs.length].min @jobs = jobs @threads = [] nr_of_threads.times do @threads << ::Thread.new do block.call(self) end end end def failed @failed ||= false end def set_failed @failed = true end def get_next_or_nil the_next = nil mutex.synchronize { the_next = @jobs.shift } the_next end def join @threads.each{|t| while not t.join(2) do end} end def mutex @mutex ||= Mutex.new end end end end
Version data entries
42 entries across 42 versions & 1 rubygems