# Copyright © 2009 William Wolf # # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . module Perform # # keep track of our threads @@threads = nil # # give access to the threads def self.threads @@threads end def perform(a_method, *args) if @@threads.nil? then # # It's the first call initialise @@threads @@threads = [] # And so install our exit handler # Make the main thread wait, note that it can still be # kill with Ctrl+C # Signal.trap "EXIT" do @@threads.each { |t| t.join } end end # # Create a new Thread # @@threads << Thread.new(self, a_method, *args) do |obj, met, *a| m = obj.method(met) m.call(*a) end end end