Class: CZTop::Z85::Pipe::Strategy::Parallel

Inherits:
CZTop::Z85::Pipe::Strategy show all
Defined in:
lib/cztop/z85/pipe.rb

Overview

Uses three threads:

  1. reads from source

  2. encodes/decodes

  3. writes to sink

This might give a performance increase on truly parallel platforms such as Rubinius and JRuby (and multiple CPU cores).

Instance Method Summary collapse

Constructor Details

#initializeParallel

Initializes the 2 sized queues used.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/cztop/z85/pipe.rb', line 128

def initialize(*)
  super
  # @source
  # |
  # V
  @source_queue = SizedQueue.new(20) # limit memory usage
  # |
  # V
  # xcode
  # |
  # V
  @sink_queue   = SizedQueue.new(20) # limit memory usage
  # |
  # V
  # @sink
end

Instance Method Details

#executeObject

Runs the algorithm.

Raises:

  • (void)


148
149
150
151
152
# File 'lib/cztop/z85/pipe.rb', line 148

def execute
  Thread.new { read }
  Thread.new { xcode }
  write
end