From: Zach Dennis Date: 2005-02-08T00:52:58+09:00 Subject: Re: Caleb, This message showed up under another, thread perhaps you replied to a message and just changed the subject heading. This makes it difficult for certain mail clients and newsreaders to correctly organize the mail in threads, next time could you compose a new email messsage to "ruby-talk@ruby-lang.org", that way more people will see your email, otherwise people may ignore the thread that this messages shows up under. thx, Zach Caleb Tennis wrote: > I've got a simple class that writes to a device on a serial port and then > reads back a response: > > class SerialPort > def write(port, arry) > file = File.new(port, File::RDWR | File::NOCTTY ) > file.write(arry.pack("C*")) > file.flush > str = file.read(50).to_s.unpack("C*") > file.close > str > end > end > > (Usage: response = SerialPort.new.write("/dev/tts/5", > [some_array_of_bytes]) ) > > The class works fine for my program, until I go multi-threaded, which is a > requirement. > > As soon as I do something this: > > Thread.new do > response = SerialPort.new.write("/dev/tts/5, [some_array_of_bytes]) > end > > The thread hangs at the read() function. If I use the same code in the > main thread it works fine. I thought at first I had resources that were > conflicting, but I've written a test case which does nothing other than > one call like seen above, and the only difference in working/not-working > is whether the code is invoked in a new thread or not. > > Any thoughts on what I might be missing here? The serial port is set to > raw mode, min 0 time 1, which means that it won't block on reads even if > no data is present. > > > >