From: Martin Ceronio Date: 2009-02-26T19:50:46+09:00 Subject: Re: Thread IO Martin Ceronio wrote: > What can I use as a general purpose duplexed IO object to communicate > via data streams between two threads? I would like something similar to > TCPSocket, but without the need to communicate via a network port. I've thought of creating two pipes (because I understand by nature that one end is read-only and the other write-only) and then giving each thread a read end and a write end, as shown below. The problem is that this hangs indefinitely, perhaps just highlighting my lack of understanding of how IO works (if that is the case, please be so kind as to put me out of my misery and point me to a good primer). So, here goes: gui_rd, ctr_wr = IO.pipe ctr_rd, gui_wr = IO.pipe gui = Thread.new(gui_rd, gui_wr) {|gui_rd, gui_wr| gui_wr << "I've got something for you\n" puts gui_rd.gets } ctr = Thread.new(ctr_rd, ctr_wr) {|ctr_rd, ctr_wr| puts ctr_rd.gets ctr_wr << "Right back at you\n" } gui.join ctr.join -- Posted via http://www.ruby-forum.com/.