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)’, &block ).
-
.help ⇒ Object
Display Usage for this Module.
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
44 45 46 47 48 |
# File 'lib/pwn/plugins/thread_pool.rb', line 44 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)', &block)
Example: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] PWN::Plugins::ThreadPool.fill(enumerable_array: arr, max_threads: 9) do |integer|
puts integerend
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pwn/plugins/thread_pool.rb', line 20 public_class_method def self.fill(opts = {}) enumerable_array = opts[:enumerable_array] opts[:max_threads].nil? ? max_threads = 9 : max_threads = opts[:max_threads].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) == :END yield this_thread end end end enumerable_array.uniq.sort.each { |this_thread| queue << this_thread } max_threads.times { queue << :END } threads.each(&:join) rescue Interrupt puts "\nGoodbye." rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pwn/plugins/thread_pool.rb', line 52 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 |