class Regextest::Back::WorkThread

Attributes

thread_id[R]

Public Class Methods

new(thread_id, initial_data = nil) click to toggle source
# File lib/regextest/back/work-thread.rb, line 11
def initialize(thread_id, initial_data = nil)
  @thread_id = thread_id
  @data = initial_data
  @r_queue = Queue.new
  @s_queue = Queue.new
  @proc = nil
end

Public Instance Methods

confirm() click to toggle source

Confirm data from child thread (executed in parent thread)

# File lib/regextest/back/work-thread.rb, line 46
def confirm
  @s_queue.pop
end
exit() click to toggle source

Exit thread (executed in child thread)

# File lib/regextest/back/work-thread.rb, line 68
def exit
  respond(:THR_CMD_EXIT)
end
exit?(data) click to toggle source
# File lib/regextest/back/work-thread.rb, line 72
def exit?(data)
  data == :THR_CMD_EXIT
end
indicate() click to toggle source

Indicate data from parent thread (executed in child thread)

# File lib/regextest/back/work-thread.rb, line 36
def indicate
  @r_queue.pop
end
request(data) click to toggle source

Request data to child thread (executed in parent thread)

# File lib/regextest/back/work-thread.rb, line 31
def request(data)
  @r_queue.push(data)
end
respond(data) click to toggle source

Respond data to parent thread (executed in child thread)

# File lib/regextest/back/work-thread.rb, line 41
def respond(data)
  @s_queue.push(data)
end
run(&proc) click to toggle source

Set procedure

# File lib/regextest/back/work-thread.rb, line 22
def run(&proc)
  @proc = proc
  @thread = Thread.new {
    Thread.abort_on_exception = true
    @proc.call(@data)
  }
end
start() click to toggle source

Start child’s thread (executed in parent thread)

# File lib/regextest/back/work-thread.rb, line 57
def start
  request(:THR_CMD_START)
end
terminate() click to toggle source

Terminate child’s thread (executed in parent thread)

# File lib/regextest/back/work-thread.rb, line 62
def terminate
  request(:THR_CMD_TERMINATE)
  @thread.join
end
wait() click to toggle source

Wait to start (executed in child thread)

# File lib/regextest/back/work-thread.rb, line 51
def wait
  data = indicate
  raise ("invalid wait. received data is #{data}") if(data != :THR_CMD_START)
end