From: Stepan Kasal Date: Mon, 28 Apr 2014 11:42:24 GMT Subject: [PATCH] poll/select: prevent busy-waiting Message-ID: <20140428114224.GA11186@camelia.ucw.cz> In-Reply-To: <20140428113815.GA10559@camelia.ucw.cz> From: Paolo Bonzini Date: Mon, 21 May 2012 09:52:42 +0200 Backported from Gnulib. 2012-05-21 Paolo Bonzini poll/select: 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. * lib/poll.c: Use SleepEx(1, TRUE) instead of SwitchToThread(). Patch from Theodore Leblond. * lib/select.c: Split polling out of the loop that sets the output fd_sets. Check for zero result and loop if the wait timeout is infinite. Signed-off-by: Stepan Kasal --- compat/poll/poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/poll/poll.c b/compat/poll/poll.c index 31163f2..a9b41d8 100644 --- a/compat/poll/poll.c +++ b/compat/poll/poll.c @@ -605,7 +605,7 @@ restart: if (!rc && timeout == INFTIM) { - SwitchToThread(); + SleepEx (1, TRUE); goto restart; } -- 1.9.2.msysgit.0.158.g6070cee