bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] poll: prevent busy-waiting


From: Erik Faye-Lund
Subject: [PATCH] poll: prevent busy-waiting
Date: Wed, 16 May 2012 21:16:14 +0200

From: theoleblond <address@hidden>

SwitchToThread() only gives away the rest of the current time
slice to another thread in the current process. So if the
thread that feeds the file decscriptor we're polling is not
in the current process, we get busy-waiting. This can lead
to very poor performance in some cases, so we better just
wait a tiny amount instead.

* lib/poll.c: use SleepEx(1, TRUE) instead of SwitchToThread()
---

Here's a patch we've applied to Git for Windows. Perhaps it's
useful upstream as well?

I'm forwarding it on behalf of Theodore, who was nice enough
to debug a performance issue and nail down a fix. Thanks,
Theodore!

 ChangeLog  | 13 +++++++++++++
 lib/poll.c |  3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index aeb3cf8..b94c311 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-05-16  theoleblond  <address@hidden>
+
+       poll: prevent busy-waiting
+
+       SwitchToThread() only gives away the rest of the current time
+       slice to another thread in the current process. So if the
+       thread that feeds the file decscriptor we're polling is not
+       in the current process, we get busy-waiting. This can lead
+       to very poor performance in some cases, so we better just
+       wait a tiny amount instead.
+
+       * lib/poll.c: use SleepEx(1, TRUE) instead of SwitchToThread()
+
 2012-05-15  Pádraig Brady  <address@hidden>
 
        fsusage: fix block size returned on older Linux 2.6
diff --git a/lib/poll.c b/lib/poll.c
index 3071b12..235338e 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -598,7 +598,8 @@ restart:
 
   if (!rc && timeout == INFTIM)
     {
-      SwitchToThread();
+      /* Sleep 1 millisecond to avoid busy wait */
+      SleepEx(1, TRUE);
       goto restart;
     }
 
-- 
1.7.10.msysgit.1.1147.g20e60f3




reply via email to

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