cygwin source-patch fixing deadlock while writing to serial port

Dave Korn dk@artimi.com
Tue Jan 20 11:28:00 GMT 2004


> -----Original Message-----
> From: cygwin-owner@cygwin.com On Behalf Of Brian Ford
> On Tue, 20 Jan 2004, H. Henning Schmidt wrote:
 
> > Ok, I will be happy to learn what the proper fix looks like 
> in your opinion.
> >
> When I can get to that code, I'll post it.

  I'll just second the notion that a crude fake-timeout-counter is a bit too
kludgey, and there will be a better solution.

> > However, I have a hard time accepting the fact that I 
> cannot write OUT 
> > the serial port because my INput buffer overflows. At least when I 
> > have switched off all kinds of flow control (which I have), then I 
> > consider these to be two independent streams that happen to 
> share one 
> > filedesc. Or should I perhaps open two independent 
> filedescriptors in 
> > this case, one write-only, one read-only?
> >
> > Are you saying that the underlying Win-API enforces what you state 
> > above, or does this really make sense in some way and I just didn't 
> > get it yet? Your statement sounds to me like I am forced to keep a 
> > second thread around, and if only to get me out of that 
> trap, once I get hung there ... does not sound too elegant to me ...
> >
> Yes.  I was stating the limitations of the Win-API.

  I've also encountered this behaviour.  Opening separate handles
unfortunately isn't an answer (at least in win32, anyway) because you're
required to open serial port descriptors in exclusive access mode, at least
according to MSDN.  (I don't know if cygwin does any kind of multiplexing of
multiple posix fds to a single win32 serial handle under the bonnet - if so,
it might work on cygwin.)

  You also can't do independent reads and writes from separate threads: the
operations are serialized, and only one input or output can be in process at
a time.  Which means that if you've got a blocking read in progress, any
write you try at the same time will wait for the read to complete :(  This
is pretty poor behaviour from the win32 api IMO, I remember that even some
of the earliest 300 baud modems were capable of *full* duplex!

  However, this all goes out the window if you open the serial port handle
for overlapped I/O, and use overlapped reads and writes.  You then get
exactly the sort of behaviour that I think Henning is looking for.  I think
this might be the long term solution Brian's thinking of; it seems to me
it'd be possible to use overlapped I/O to provide all the features of the
posix termios api.


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list