[gtkmm-documentation] Input example: Fix high CPU load



commit 6d3268e60f8d7f9b28373af9ac6c672c4c6964d3
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sat Sep 26 11:03:08 2015 +0200

    Input example: Fix high CPU load
    
    * examples/book/input/main.cc: Open the fifo in read/write mode, or else
    the program unnecessarily uses a lot of CPU time.

 examples/book/input/main.cc |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/examples/book/input/main.cc b/examples/book/input/main.cc
index a7733e3..1307272 100644
--- a/examples/book/input/main.cc
+++ b/examples/book/input/main.cc
@@ -62,7 +62,13 @@ int main(int argc, char *argv[])
     #endif //HAVE_MKFIFO
   }
 
-  read_fd = open("testfifo", O_RDONLY);
+  // Although we will only read from the fifo, we open it in read/write mode.
+  // Due to a peculiarity with the poll() system call, used deep down in glib,
+  // this small program will use all available CPU time, if the fifo is opened
+  // as O_RDONLY. See a discussion on the gtkmm-list, e.g.
+  // https://mail.gnome.org/archives/gtkmm-list/2015-September/msg00034.html
+  // and the link from there to stackoverflow.
+  read_fd = open("testfifo", O_RDWR);
   if (read_fd == -1)
   {
     std::cerr << "error opening fifo" << std::endl;


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