File tree 2 files changed +34
-30
lines changed
2 files changed +34
-30
lines changed Original file line number Diff line number Diff line change 1
1
require 'thread'
2
2
require 'socket'
3
-
4
- class Pool
5
- def initialize ( size )
6
- @size = size
7
- @jobs = Queue . new
8
- @pool = Array . new ( @size ) do |i |
9
- Thread . new do
10
- Thread . current [ :id ] = i
11
- catch ( :exit ) do
12
- loop do
13
- job , args = @jobs . pop
14
- job . call ( *args )
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
- def schedule ( *args , &block )
22
- @jobs << [ block , args ]
23
- end
24
-
25
- def shutdown
26
- @size . times do
27
- schedule { throw :exit }
28
- end
29
-
30
- @pool . map ( &:join )
31
- end
32
- end
3
+ require_relative 'thread-pool.rb'
33
4
34
5
unless ARGV . length == 2
35
6
puts 'Usage: ruby generator.rb host_address host_ port'
Original file line number Diff line number Diff line change
1
+ # This code was found http://burgestrand.se/code/ruby-thread-pool/
2
+ # Decided to use this pool implementation then creating my own
3
+
4
+ class Pool
5
+ def initialize ( size )
6
+ @size = size
7
+ @jobs = Queue . new
8
+ @pool = Array . new ( @size ) do |i |
9
+ Thread . new do
10
+ Thread . current [ :id ] = i
11
+ catch ( :exit ) do
12
+ loop do
13
+ job , args = @jobs . pop
14
+ job . call ( *args )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def schedule ( *args , &block )
22
+ @jobs << [ block , args ]
23
+ end
24
+
25
+ def shutdown
26
+ @size . times do
27
+ schedule { throw :exit }
28
+ end
29
+
30
+ @pool . map ( &:join )
31
+ end
32
+ end
33
+
You can’t perform that action at this time.
0 commit comments