Sha256: f13efe62ab6a53fc8f0e8e2035a974cb986abaa672291b835e47f58797638bb9
Contents?: true
Size: 800 Bytes
Versions: 36
Compression:
Stored size: 800 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
36 entries across 36 versions & 1 rubygems