[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    
From:       "Caleb Tennis" <caleb () aei-tech ! com>
Date:       2005-02-07 14:30:57
Message-ID: 39439.192.168.2.71.1107786643.squirrel () 192 ! 168 ! 2 ! 71
[Download RAW message or body]

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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic