[glibmm] examples/tests: Use simpler std::thread constructor.



commit eb2117327fa1a74f3f44a4acd227a2c836c48b38
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Nov 26 10:26:07 2015 +0100

    examples/tests: Use simpler std::thread constructor.
    
    Instead of using a lambda. As suggested by Kjell Ahlstedt:
    https://bugzilla.gnome.org/show_bug.cgi?id=757674#c10

 examples/network/resolver.cc      |    6 +-----
 examples/network/socket-client.cc |    6 +-----
 examples/network/socket-server.cc |    6 +-----
 examples/thread/thread.cc         |   14 ++++----------
 tests/glibmm_mainloop/main.cc     |    7 ++-----
 5 files changed, 9 insertions(+), 30 deletions(-)
---
diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc
index e6837b2..5750479 100644
--- a/examples/network/resolver.cc
+++ b/examples/network/resolver.cc
@@ -209,11 +209,7 @@ start_threaded_lookups (char **argv, int argc)
   for (auto i = 0; i < argc; i++)
   {
     const Glib::ustring arg = argv[i];
-    const auto thread = new std::thread(
-      [arg]
-      {
-        lookup_thread(arg);
-      });
+    const auto thread = new std::thread(&lookup_thread, arg);
     result.push_back(thread);
   }
 
diff --git a/examples/network/socket-client.cc b/examples/network/socket-client.cc
index 9204a25..ebde5b6 100644
--- a/examples/network/socket-client.cc
+++ b/examples/network/socket-client.cc
@@ -164,11 +164,7 @@ main (int argc,
     if (cancel_timeout)
     {
         cancellable = Gio::Cancellable::create ();
-        thread = new std::thread(
-          [cancellable] ()
-          {
-            cancel_thread(cancellable);
-          });
+        thread = new std::thread(&cancel_thread, cancellable);
     }
 
     loop = Glib::MainLoop::create ();
diff --git a/examples/network/socket-server.cc b/examples/network/socket-server.cc
index dcca8c5..43c0e6e 100644
--- a/examples/network/socket-server.cc
+++ b/examples/network/socket-server.cc
@@ -152,11 +152,7 @@ main (int argc,
     if (cancel_timeout)
     {
         cancellable = Gio::Cancellable::create ();
-        thread = new std::thread(
-          [cancellable] ()
-          {
-            cancel_thread(cancellable);
-          });
+        thread = new std::thread(&cancel_thread, cancellable);
     }
 
     loop = Glib::MainLoop::create ();
diff --git a/examples/thread/thread.cc b/examples/thread/thread.cc
index e99de76..816e7c7 100644
--- a/examples/thread/thread.cc
+++ b/examples/thread/thread.cc
@@ -112,17 +112,11 @@ int main(int, char**)
   MessageQueue queue;
 
   //TODO: Use std::make_unique() when we use C++14:
-  const auto producer = std::unique_ptr<std::thread>(new std::thread(
-    [&queue] ()
-    {
-      queue.producer();
-    }));
+  const auto producer = std::unique_ptr<std::thread>(
+    new std::thread(&MessageQueue::producer, &queue));
 
-   const auto consumer = std::unique_ptr<std::thread>(new std::thread(
-    [&queue] ()
-    {
-      queue.consumer();
-    }));
+  const auto consumer = std::unique_ptr<std::thread>(
+    new std::thread(&MessageQueue::consumer, &queue));
 
   producer->join();
   consumer->join();
diff --git a/tests/glibmm_mainloop/main.cc b/tests/glibmm_mainloop/main.cc
index 5a43754..fab8575 100644
--- a/tests/glibmm_mainloop/main.cc
+++ b/tests/glibmm_mainloop/main.cc
@@ -86,11 +86,8 @@ int main(int, char**)
 
   // Create a second thread.
   const std::thread::id first_thread_id = std::this_thread::get_id();
-  std::thread* second_thread = new std::thread(
-    [first_thread_id, first_mainloop]
-    {
-      thread_function(first_thread_id, first_mainloop);
-    });
+  std::thread* second_thread =
+    new std::thread(&thread_function, first_thread_id, first_mainloop);
 
   // Start the first main loop.
   first_mainloop->run();


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