emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114068: A possible fix for bug #14333 with hanging


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r114068: A possible fix for bug #14333 with hanging at exit on MS-Windows.
Date: Thu, 29 Aug 2013 15:32:57 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114068
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/14333
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Thu 2013-08-29 18:32:04 +0300
message:
  A possible fix for bug #14333 with hanging at exit on MS-Windows.
  
   src/w32.c (term_winsock): Call release_listen_threads before calling
   WSACleanup.
   (_sys_wait_accept): Wait for accept event in a loop with a finite
   timeout, instead of waiting indefinitely.  Will hopefully avoid
   hanging during exit because WSACleanup deadlocks waiting for the
   event object to be released.
   src/w32proc.c (release_listen_threads): New function, signals all
   the reader threads that listen for connections to stop waiting.
   src/w32.h (release_listen_threads): Add prototype.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/w32.c                      w32.c-20091113204419-o5vbwnq5f7feedwu-808
  src/w32.h                      w32.h-20091113204419-o5vbwnq5f7feedwu-809
  src/w32proc.c                  w32proc.c-20091113204419-o5vbwnq5f7feedwu-814
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-08-29 15:28:45 +0000
+++ b/src/ChangeLog     2013-08-29 15:32:04 +0000
@@ -1,3 +1,17 @@
+2013-08-29  Eli Zaretskii  <address@hidden>
+
+       * w32.c (term_winsock): Call release_listen_threads before calling
+       WSACleanup.
+       (_sys_wait_accept): Wait for accept event in a loop with a finite
+       timeout, instead of waiting indefinitely.  Will hopefully avoid
+       hanging during exit because WSACleanup deadlocks waiting for the
+       event object to be released.  (Bug#14333)
+
+       * w32proc.c (release_listen_threads): New function, signals all
+       the reader threads that listen for connections to stop waiting.
+
+       * w32.h (release_listen_threads): Add prototype.
+
 2013-08-29  Dmitry Antipov  <address@hidden>
 
        * alloc.c (Fmake_marker, build_marker): Zero need_adjustment

=== modified file 'src/w32.c'
--- a/src/w32.c 2013-08-27 18:47:55 +0000
+++ b/src/w32.c 2013-08-29 15:32:04 +0000
@@ -6092,6 +6092,7 @@
 {
   if (winsock_lib != NULL && winsock_inuse == 0)
     {
+      release_listen_threads ();
       /* Not sure what would cause WSAENETDOWN, or even if it can happen
         after WSAStartup returns successfully, but it seems reasonable
         to allow unloading winsock anyway in that case. */
@@ -7076,7 +7077,12 @@
   rc = pfn_WSAEventSelect (SOCK_HANDLE (fd), hEv, FD_ACCEPT);
   if (rc != SOCKET_ERROR)
     {
-      rc = WaitForSingleObject (hEv, INFINITE);
+      do {
+       rc = WaitForSingleObject (hEv, 500);
+       Sleep (5);
+      } while (rc == WAIT_TIMEOUT
+              && cp->status != STATUS_READ_ERROR
+              && cp->char_avail);
       pfn_WSAEventSelect (SOCK_HANDLE (fd), NULL, 0);
       if (rc == WAIT_OBJECT_0)
        cp->status = STATUS_READ_SUCCEEDED;

=== modified file 'src/w32.h'
--- a/src/w32.h 2013-07-07 18:00:14 +0000
+++ b/src/w32.h 2013-08-29 15:32:04 +0000
@@ -163,6 +163,7 @@
 /* Return the string resource associated with KEY of type TYPE.  */
 extern LPBYTE w32_get_resource (char * key, LPDWORD type);
 
+extern void release_listen_threads (void);
 extern void init_ntproc (int);
 extern void term_ntproc (int);
 extern void globals_of_w32 (void);

=== modified file 'src/w32proc.c'
--- a/src/w32proc.c     2013-08-27 18:47:55 +0000
+++ b/src/w32proc.c     2013-08-29 15:32:04 +0000
@@ -990,6 +990,18 @@
   return NULL;
 }
 
+void
+release_listen_threads (void)
+{
+  int i;
+
+  for (i = child_proc_count - 1; i >= 0; i--)
+    {
+      if (CHILD_ACTIVE (&child_procs[i])
+         && (fd_info[child_procs[i].fd].flags & FILE_LISTEN))
+       child_procs[i].status = STATUS_READ_ERROR;
+    }
+}
 
 /* Thread proc for child process and socket reader threads. Each thread
    is normally blocked until woken by select() to check for input by


reply via email to

[Prev in Thread] Current Thread [Next in Thread]