git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] poll/select: prevent busy-waiting

From
Stepan Kasal <kasal@ucw.cz>
Date
Apr 28, 2014, 11:42 UTC
Message-ID
<20140428114224.GA11186@camelia.ucw.cz>
In-Reply-To
<20140428113815.GA10559@camelia.ucw.cz>
From: Paolo Bonzini <bonzini@gnu.org>
Date: Mon, 21 May 2012 09:52:42 +0200
Backported from Gnulib.
2012-05-21  Paolo Bonzini  <bonzini@gnu.org>
	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 <kasal@ucw.cz>
---
 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
Previous: Stepan KasalNext: Erik Faye-Lund
Message 4 of 18 in “Sleep 1 millisecond in poll() to avoid busy wait”
  1. Sleep 1 millisecond in poll() to avoid busy waitStepan Kasal, Apr 28, 2014
  2. Erik Faye-LundApr 28, 2014
  3. Stepan KasalApr 28, 2014
  4. poll/select: prevent busy-waitingStepan Kasal, Apr 28, 2014
  5. Erik Faye-LundApr 28, 2014
  6. Windows: Always normalize paths to Windows-styleStepan Kasal, Apr 28, 2014
  7. Stepan KasalApr 28, 2014
  8. Heiko VoigtMay 7, 2014
  9. Junio C HamanoMay 7, 2014
  10. Stepan KasalMay 8, 2014
  11. Junio C HamanoMay 8, 2014
  12. Revert "submodules: fix ambiguous absolute paths under Windows"Stepan Kasal, May 8, 2014
  13. Johannes SixtApr 28, 2014
  14. Sleep 1 millisecond in poll() to avoid busy waitStepan Kasal, Apr 28, 2014
  15. Erik Faye-LundApr 28, 2014
  16. Junio C HamanoApr 28, 2014
  17. Stepan KasalApr 29, 2014
  18. Junio C HamanoApr 29, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.