From: Jamis Buck Date: 2004-09-12T02:47:30+09:00 Subject: Re: Net-SSH Threaded PortForward Script Problems otaku wrote: > Justin, > > advise taken investigating > i am wondering why it dies > with only 1 thread > i scaled the script down to > 1 thread > which should not be creating any race condition > so i am becoming confused with this one > i think i will leave it alone for a while > and come back to it If you are doing even one call to Thread.new, then there are always at least two threads: the new one, and the main one (which started the new one). And if you're dealing with more than one thread, you are faced with the possibility of race conditions. Consider: Your main thread (A) starts. It spawns a new thread (B) and continues on. B is intended to start a forwarded port. Before thread B can begin executing, A does Net::SSH.start to connect to the forwarded port that B was supposed to start, but B hasn't started it yet. Hence, a race condition. This is where the condition variable is necessary. You let B signal A that it has started the server and set up a forwarded port. A waits until it receives that signal, and once it does, it then tries to connect. This way, you know that A never tries to connect until the forwarded ports are available. Does that make sense? - Jamis -- 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."