last day (15 days later) » 

8:43 PM
1
A: Why the exit function doesn't actually terminate the program

jeffluntI think exit in that scope is running Thread#exit instead of Kernel#exit (as you are expecting). I'm using Ruby 2.1.2, however, so perhaps the behavior is a bit different. You can see this by running the code: 2.1.0 :007 > Thread.new do 2.1.0 :008 > puts self.inspect 2.1.0 :009?> end main =

 
So, I need to call the Kernel#exit function manually like this -- Kernel.exit?
 
Yeah. I clarified my answer with updated code.
 
No, I've got the same output even in case of Kernel#exit function call
 
I was just trying to clarify which method is actually being called, which matters. I'll take another look at your question.
 
Yeah, thanks a lot for this! Anyway, I'm waiting for the answer
 
8:43 PM
I added one more clarifying thing. There may be a difference in this case between the implementation in 2.0.0 vs 2.1.0 (which I'm using). Interesting.
 
Thanks a lot! Can you find any confirmation about it, please?
 
I don't have Ruby 2.0.0 installed, but if you run my example test.rb file, and in one case use Kernel::exit and try it again with Thread::exit what do you get?
I've tested the ruby 2.1.0 path - since you have 2.0.0 installed - can you run that test file and post your results?
 
ofc, wait a minute, please
In case of Kernel::exit the application is immediately shutdown and in case of Thread::exit I've got the following error:
in `gets': No such file or directory - 127.0.0.1 (Errno::ENOENT)
 
Replace the "gets" with some other command - I just put that in there for kicks.
It doesn't really matter what's done inside the while loop.
 
I replaced it with the Curses.getch function call and Thread::exit kills only one thread, allowing me to input characters indefinitely
So,
Then I have the following code:

first = Thread.new do
loop {
Curses.getch
}
end

second = Thread.new do
Kernel::exit
end

second.join
first.join
When*
The application will wait for the next user input
However, if I replace Curses.getch with the gets.chomp, it doesn't wait anything and shutdown immediately
 
9:01 PM
So, I wonder what role Curses is playing in this.
 
Me too
 
I have a basic idea of what the Curses library does, but I haven't personally used it, so I don't know much about the initialization process.
 
Where should I ask about it? Maybe there's some king of usenet group / mail list of ruby curses module?
 
But it sounds like there's some kind of interplay between when those threads happen to start and the Curses initialization/exit code that's making the situation more complicated than it appears on the surface.
As a side question, what's your reason for using threads?
 
I need it to implement anonymous_chat -- bitbucket.org/ntrophimov/anonymous_chat
 
9:04 PM
ah, so this is a command-line driven app where there's a thread for updating the other chat messages and a thread for dealing with user typing?
 
Yes
 
hm, well now you're going to stretch my knowledge of ruby's threading model
have you done multi-threaded apps before, and if so in what language?
 
Yep, C++, Objective-C, etc
 
I guess to answer your quick question - yes I would start by finding a curses mailing list (for the ruby implementation) - and asking them
that's probably going to get you an answer about if/how there's an interaction
*probably going to get you an answer faster than talking to me :(
since I've not used curses before
 
Thanks a lot, man!
btw where r u from?
 
That's great :)
 
It's a fine town.
you?
 
Russia :)
 
nice
 
Oh, I don't think so :)
Do you have Skype?
No for voice chat, don't worry :)
Not*
 
9:18 PM
um...I think I have it installed somewhere, but I don't really use it
I'm one of those email people
 
Can I get your email?
 
yeah, it's in my profile
 
Thanks!
Thanks a lot again! cya :)
btw, check it out -- ruby-forum.com/topic/5437509#new
 

last day (15 days later) »