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

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



53
54
55
56
57
# File 'lib/pwn/plugins/thread_pool.rb', line 53

public_class_method def self.authors
  "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)',
detach: 'optional boolean to detach threads (defaults to false)'

)

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



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
# File 'lib/pwn/plugins/thread_pool.rb', line 25

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?
  detach = opts[:detach] ||= false

  puts "Initiating Thread Pool of #{max_threads} Worker Threads...."
  pool = Concurrent::FixedThreadPool.new(max_threads)

  enumerable_array.each do |this_thread|
    pool.post do
      yield this_thread
    end
  end

  pool.shutdown
  pool.wait_for_termination unless detach
rescue Interrupt
  puts "\n#{self}.#{__method__} => Goodbye."
rescue StandardError => e
  puts e.backtrace
  raise e
ensure
  pool.kill if pool.running?
end

.helpObject

Display Usage for this Module



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pwn/plugins/thread_pool.rb', line 61

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)',
      detach: 'optional boolean to detach threads (defaults to false)'
    )

    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