Net-SSH Threaded PortForward Script Problems

Justin,

i am not sure the syntax is correct
however its looking like perhaps you may be correct
in regard to the race condition

the Programming Ruby book provides an example of using mutex

require 'thread'
mutex = Mutex.new

count1 = count2 = 0
difference = 0
counter = Thread.new do
loop do
mutex.synchronize do
count1 += 1
count2 += 1
end
end
end
spy = Thread.new do
loop do
mutex.synchronize do
difference += (count1 - count2).abs
    end
  end
end

otaku wrote:

Justin,

i am not sure the syntax is correct
however its looking like perhaps you may be correct
in regard to the race condition

the Programming Ruby book provides an example of using mutex

[snip]

You want more than just a mutex, though--you need a condition variable. The CV lets you wait until some other condition has been satisfied (it's useful for helping to prevent deadlocks):

   require 'thread'

   m = Mutex.new
   cv = ConditionVariable.new

   Thread.new do
     m.synchronize do
       # do some work
       cv.signal
     end
   end

   # wait until the cv is signaled
   m.synchronize { cv.wait( m ) }

Justin was saying you need to use a condition variable to let your program know that the threads have all started properly, and are ready to accept connections.

···

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."

jamis,

cool now i am tracking
working on it

this is good its forcing me to understand on a preliminary level
threading in ruby

thank you