make the serial port access thread-safe.