[squeak-dev] Serial Port(s) from multiple processes

Jon Hylands jon at huv.com
Thu Jun 11 20:16:06 UTC 2009


Hi everyone,

I've got a couple USB-based serial ports on my robot BrainBot, and I've got
four different processes - two for each port. One process reads from the
serial port, and one writes to it.

For each serial port, I have a mutex semaphore to protect access to the
port, like this:

readData
	^portAccess critical: [serialPort readByteArray]

writeData: aByteArray
	portAccess critical: [serialPort nextPutAll: aByteArray]

Those two methods are implemented in the same class, and thus the
'portAccess' instance variable (which is a Semaphore) is shared between
read and write, but not between different serial ports..

I have two instances of this class, one for each USB device plugged in (the
USB devices are both FT232-based interfaces, one at port 4, the other at
port 5).

The question is, do I need to protect the two instances of SerialPort with
a single Semaphore? Looking at the serial port code for read/writing, it
looks like the code just jumps directly into the primitives. I was under
the assumption that primitive execution can't be pre-empted, and therefore
the code shouldn't need mutex protection.

Am I missing something?

Thanks,
Jon

--------------------------------------------------------------
   Jon Hylands      Jon at huv.com      http://www.huv.com/jon

  Project: Micro Raptor (Small Biped Velociraptor Robot)
           http://www.huv.com/blog



More information about the Squeak-dev mailing list