Skip to contentSkip to conversation

aio: avoid livelock behavior for Win32

PATCH Applied Paolo Bonzini 2 participants 2 messages Nov 23, 2012 – Nov 26, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aio: avoid livelock behavior for Win32

The repeated calls to WaitForMultipleObjects may cause a livelock in aio_poll, where no progress is made on bottom halves. This patch matches the behavior of the POSIX code.

---
Found by the new unit tests.

 aio-win32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
aio-win32.c +4 -1
index a84eb71..cec4646 100644
@@ -173,7 +173,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
     }
 
     /* wait until next event */
-    for (;;) {
+    while (count > 0) {
         int timeout = blocking ? INFINITE : 0;
         int ret = WaitForMultipleObjects(count, events, FALSE, timeout);
 
@@ -209,6 +209,9 @@ bool aio_poll(AioContext *ctx, bool blocking)
                 g_free(tmp);
             }
         }
+
+        /* Try again, but only call each handler once.  */
+        events[ret - WAIT_OBJECT_0] = events[--count];
     }
 
     return progress;
Signature · 1 line
1.8.0
#1 lore raw
Quoted 7 lines · Paolo Bonzini

The repeated calls to WaitForMultipleObjects may cause a livelock in aio_poll, where no progress is made on bottom halves. This patch matches the behavior of the POSIX code.

---
Found by the new unit tests.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 29 lines
 aio-win32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
aio-win32.c +4 -1
index a84eb71..cec4646 100644
@@ -173,7 +173,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
     }
 
     /* wait until next event */
-    for (;;) {
+    while (count > 0) {
         int timeout = blocking ? INFINITE : 0;
         int ret = WaitForMultipleObjects(count, events, FALSE, timeout);
 
@@ -209,6 +209,9 @@ bool aio_poll(AioContext *ctx, bool blocking)
                 g_free(tmp);
             }
         }
+
+        /* Try again, but only call each handler once.  */
+        events[ret - WAIT_OBJECT_0] = events[--count];
     }
 
     return progress;
Signature · 1 line
1.8.0