Module: PWN::Plugins::ThreadPool
- Defined in:
- lib/pwn/plugins/thread_pool.rb
Overview
This plugin makes the creation of a thread pool much simpler.
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.fill(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::ThreadPool.fill( enumerable_array: ‘required array for proper thread pool assignment’, max_threads: ‘optional number of threads in the thread pool (defaults to 9)’, seconds_between_thread_exec: ‘optional - time to sleep between thread execution (defaults to 0)’ &block ).
-
.help ⇒ Object
Display Usage for this Module.
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
61 62 63 64 65 |
# File 'lib/pwn/plugins/thread_pool.rb', line 61 public_class_method def self. "AUTHOR(S): 0day Inc. <[email protected]> " end |
.fill(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::ThreadPool.fill(
enumerable_array: 'required array for proper thread pool assignment', max_threads: 'optional number of threads in the thread pool (defaults to 9)', seconds_between_thread_exec: 'optional - time to sleep between thread execution (defaults to 0)' &block
)
Example: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] mutex = Mutex.new PWN::Plugins::ThreadPool.fill(enumerable_array: arr, max_threads: 9) do |integer|
mutex.synchronize do puts integer end
end
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pwn/plugins/thread_pool.rb', line 24 public_class_method def self.fill(opts = {}) enumerable_array = opts[:enumerable_array] max_threads = opts[:max_threads].to_i max_threads = 9 if max_threads.zero? # seconds_between_thread_exec = opts[:seconds_between_thread_exec].to_i puts "Initiating Thread Pool of #{max_threads} Worker Threads...." queue = SizedQueue.new(max_threads) threads = Array.new(max_threads) do Thread.new do until (this_thread = queue.pop) == :POOL_EXHAUSTED yield this_thread end end end enumerable_array.uniq.sort.each do |this_thread| queue << this_thread end max_threads.times do queue << :POOL_EXHAUSTED end # threads.each do |thread| # sleep seconds_between_thread_exec if seconds_between_thread_exec.positive? # thread.join # end threads.each(&:join) rescue Interrupt puts "\nGoodbye." rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pwn/plugins/thread_pool.rb', line 69 public_class_method def self.help puts "USAGE: #{self}.fill( enumerable_array. => 'required array for proper thread pool assignment', max_threads: 'optional number of threads in the thread pool (defaults to 9)', &block ) Example: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] #{self}.fill(enumerable_array: arr, max_threads: 9) do |integer| puts integer end #{self}.authors " end |