Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <400C4757.3060208@hhschmidt.de> Date: Mon, 19 Jan 2004 22:08:39 +0100 From: "H. Henning Schmidt" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: cygwin source-patch fixing deadlock while writing to serial port Content-Type: multipart/mixed; boundary="------------050409090808050008090604" X-Provags-ID: kundenserver.de abuse AT kundenserver DOT de auth:e9b0f294f4b6d6da7efd4652948020da --------------050409090808050008090604 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit I found a potential deadlock while writing to a serial port (e.g. /dev/com1) that has been opened as O_RDWR. The deadlock occurs from time to time (not sure about exact conditions) when I write to that port, while there is data coming in (e.g. from an external device) and I do not read away that data fast enough from the port. I did provide a test case a while ago in http://sources.redhat.com/ml/cygwin/2003-03/msg01529.html. I digged into the issue some more now and found that the executing thread got sometimes deadlocked in fhandler_serial::raw_write(). It basically ends up in a for(;;) loop and just never hits the break; The applied patch adds a safety exit to that for(;;) loop. This fixes the testcase referenced above. This might not be the last problem lingering in the serial access code (there are some FIXME tokens still around ...), but it is definitely an improvement for me. I thought I'd share that with you. ;Henning -- H. Henning Schmidt email: henning AT hhschmidt DOT de phone: +49 (0) 6155 / 899 283 fax: +49 (0) 6155 / 899 284 --------------050409090808050008090604 Content-Type: text/plain; name="patch.cygwin-1.5.5-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.cygwin-1.5.5-1" *** cygwin-1.5.5-1/winsup/cygwin/fhandler_serial.cc Sat Jun 21 02:12:35 2003 --- cygwin-1.5.5-1.corrected/winsup/cygwin/fhandler_serial.cc Mon Jan 19 17:32:04 2004 *************** *** 153,173 **** int fhandler_serial::raw_write (const void *ptr, size_t len) { ! DWORD bytes_written; OVERLAPPED write_status; memset (&write_status, 0, sizeof (write_status)); write_status.hEvent = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); ProtectHandle (write_status.hEvent); ! for (;;) { if (WriteFile (get_handle (), ptr, len, &bytes_written, &write_status)) break; switch (GetLastError ()) { case ERROR_OPERATION_ABORTED: continue; case ERROR_IO_PENDING: break; --- 153,174 ---- int fhandler_serial::raw_write (const void *ptr, size_t len) { ! DWORD bytes_written = 0; OVERLAPPED write_status; memset (&write_status, 0, sizeof (write_status)); write_status.hEvent = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); ProtectHandle (write_status.hEvent); ! for (int prevent_deadlock=0 ; prevent_deadlock<10 ; prevent_deadlock++) { if (WriteFile (get_handle (), ptr, len, &bytes_written, &write_status)) break; switch (GetLastError ()) { case ERROR_OPERATION_ABORTED: + bytes_written = 0; continue; case ERROR_IO_PENDING: break; --------------050409090808050008090604 Content-Type: text/plain; charset=us-ascii -- 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/ --------------050409090808050008090604--