From: Dylan Evans Date: 2009-02-26T20:47:15+09:00 Subject: Re: Thread IO --001485f87056e02f0b0463d0ec9c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit That's a pretty standard way to do IPC and is generally a good idea. Also your code works for me. What ruby implementation are you using? On Thu, Feb 26, 2009 at 8:50 PM, Martin Ceronio wrote: > 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/. > > -- The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum --001485f87056e02f0b0463d0ec9c--