James Gray
6/9/2009 1:21:00 PM
On Jun 9, 2009, at 7:28 AM, Christoph Jasinski wrote:
> Thanks,
> it works; I don't know why, but it works
I know why it work. :) Let me explain:
1. Your code splits into two threads (the main Thread Ruby started
your program in and the one you created to talk to YahooFinance in)
2. After you have the two Threads, they both begin working (trading
off time)
3. Your YahooFinance Thread probably starts talking over the network
4. However, your main Thread runs off the end of your file and when
that happens, Ruby exits (killing the unfinished YahooFinance Thread)
Thus, Vikhyat had you add a line that asked the main Thread to join()
or wait on the YahooFinance Thread to finish. That call won't return
until the second Thread ends, so Ruby will wait to exit.
Of course, that means the second Thread doesn't really do anything for
us in this case. But if you are launching a bunch of them or
continuing to work in the main Thread, there will be benefits.
Hope that helps.
James Edward Gray II