summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-11-10 13:26:00 +0100
committerMurray Cumming <murrayc@murrayc.com>2016-11-14 10:43:21 +0100
commitdb75f338fb1865fbec12daae64dac4d0a1b9abf8 (patch)
treee502ea0b726f1dccd35c90660aab43d3b283e045 /examples
parent53ceee1d8f4967d4fc3a9ece73a8a273583aae5e (diff)
downloadglibmm-db75f338fb1865fbec12daae64dac4d0a1b9abf8.tar.gz
Remove deprecated Thread and Threads API.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am6
-rw-r--r--examples/thread/thread.cc126
-rw-r--r--examples/thread/threadpool.cc68
3 files changed, 1 insertions, 199 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0de871a7..885552d5 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -32,11 +32,7 @@ check_PROGRAMS = \
options/example \
properties/example \
regex/example \
- settings/settings \
- thread/dispatcher \
- thread/dispatcher2 \
- thread/thread \
- thread/threadpool
+ settings/settings
glibmm_includes = -I$(top_builddir)/glib $(if $(srcdir:.=),-I$(top_srcdir)/glib)
giomm_includes = -I$(top_builddir)/gio $(if $(srcdir:.=),-I$(top_srcdir)/gio)
diff --git a/examples/thread/thread.cc b/examples/thread/thread.cc
deleted file mode 100644
index 7af27350..00000000
--- a/examples/thread/thread.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-
-#include <condition_variable>
-#include <iostream>
-#include <memory>
-#include <mutex>
-#include <queue>
-#include <thread>
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-/* For using noexcept on Visual Studio 2013 */
-#include <glibmmconfig.h>
-#endif
-#include <glibmm/init.h>
-#include <glibmm/random.h>
-#include <glibmm/timer.h>
-
-namespace
-{
-
-class MessageQueue
-{
-public:
- MessageQueue();
- ~MessageQueue();
-
- void producer();
- void consumer();
-
-private:
- std::mutex mutex_;
- std::condition_variable cond_push_;
- std::condition_variable cond_pop_;
- std::queue<int> queue_;
-};
-
-MessageQueue::MessageQueue()
-{
-}
-
-MessageQueue::~MessageQueue()
-{
-}
-
-void
-MessageQueue::producer()
-{
- Glib::Rand rand(1234);
-
- for (auto i = 0; i < 200; ++i)
- {
- {
- std::unique_lock<std::mutex> lock(mutex_);
-
- cond_pop_.wait(lock, [this]() -> bool { return queue_.size() < 64; });
-
- queue_.push(i);
- std::cout << '*';
- std::cout.flush();
-
- // We unlock before notifying, because that is what the documentation suggests:
- // http://en.cppreference.com/w/cpp/thread/condition_variable
- lock.unlock();
- cond_push_.notify_one();
- }
-
- if (rand.get_bool())
- continue;
-
- Glib::usleep(rand.get_int_range(0, 100000));
- }
-}
-
-void
-MessageQueue::consumer()
-{
- Glib::Rand rand(4567);
-
- for (;;)
- {
- {
- std::unique_lock<std::mutex> lock(mutex_);
-
- cond_push_.wait(lock, [this]() -> bool { return !queue_.empty(); });
-
- const int i = queue_.front();
- queue_.pop();
- std::cout << "\x08 \x08";
- std::cout.flush();
-
- // We unlock before notifying, because that is what the documentation suggests:
- // http://en.cppreference.com/w/cpp/thread/condition_variable
- lock.unlock();
- cond_pop_.notify_one();
-
- if (i >= 199)
- break;
- }
-
- if (rand.get_bool())
- continue;
-
- Glib::usleep(rand.get_int_range(10000, 200000));
- }
-}
-}
-
-int
-main(int, char**)
-{
- Glib::init();
-
- MessageQueue queue;
-
- // TODO: Use std::make_unique() when we use C++14:
- 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(&MessageQueue::consumer, &queue));
-
- producer->join();
- consumer->join();
-
- std::cout << std::endl;
-
- return 0;
-}
diff --git a/examples/thread/threadpool.cc b/examples/thread/threadpool.cc
deleted file mode 100644
index 885962bc..00000000
--- a/examples/thread/threadpool.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-
-#include <iostream>
-#include <mutex>
-#include <thread>
-
-// TODO: Remove this example sometime. Glib::ThreadPool is deprecated.
-// TODO: Maybe use std::async() instead?
-#undef GLIBMM_DISABLE_DEPRECATED
-
-#include <glibmmconfig.h>
-
-#ifdef GLIBMM_DISABLE_DEPRECATED
-int
-main(int, char**)
-{
- // If glibmm is configured with --disable-deprecated-api,
- // GLIBMM_DISABLE_DEPRECATED is defined in glibmmconfig.h.
- std::cout << "Glib::ThreadPool not available because deprecated API has been disabled."
- << std::endl;
- return 77; // Tell automake's test harness to skip this test.
-}
-
-#else
-
-#include <glibmm/random.h>
-#include <glibmm/threadpool.h>
-#include <glibmm/timer.h>
-
-namespace
-{
-
-std::mutex mutex;
-
-void
-print_char(char c)
-{
- Glib::Rand rand;
-
- for (auto i = 0; i < 100; ++i)
- {
- {
- std::lock_guard<std::mutex> lock(mutex);
- std::cout << c;
- std::cout.flush();
- }
- Glib::usleep(rand.get_int_range(10000, 100000));
- }
-}
-
-} // anonymous namespace
-
-int
-main(int, char**)
-{
- Glib::ThreadPool pool(10);
-
- for (auto c = 'a'; c <= 'z'; ++c)
- {
- pool.push(sigc::bind(sigc::ptr_fun(&print_char), c));
- }
-
- pool.shutdown();
-
- std::cout << std::endl;
-
- return 0;
-}
-#endif // GLIBMM_DISABLE_DEPRECATED