ruby - Why does this code print the same thing twice? -


I'm trying to write some short timeout codes:

  t = thread New {sleep 3} # & lt; Thread that will make threads.New {sleep2; T.kill; P 'Hi!' } # & Lt; - Thread which will kill it after two seconds. If the first thread completes the work within two seconds, it will stop, and nothing will be done to do the main thread.  
This will remove the other thread from the program before the t.kill section, but when I run this code, "Hello!" prints with p gets printed twice fixes it. Why does this happen?

Ruby had a bug with no buffering and threading that looks like this. It has been fixed recently, so upgrade.


Comments