[Groonga-commit] groonga/grnxx at 50d0f67 [master] Add tests for grnxx::Thread.

Back to archive index

susumu.yata null+****@clear*****
Tue Apr 30 22:10:43 JST 2013


susumu.yata	2013-04-30 22:10:43 +0900 (Tue, 30 Apr 2013)

  New Revision: 50d0f67fd734b2de54f0930c9bf020a5ea76d327
  https://github.com/groonga/grnxx/commit/50d0f67fd734b2de54f0930c9bf020a5ea76d327

  Message:
    Add tests for grnxx::Thread.

  Modified files:
    test/test_thread.cpp

  Modified: test/test_thread.cpp (+40 -0)
===================================================================
--- test/test_thread.cpp    2013-04-30 22:04:33 +0900 (02f2be4)
+++ test/test_thread.cpp    2013-04-30 22:10:43 +0900 (25df4d5)
@@ -17,11 +17,23 @@
 */
 #include <cassert>
 
+#include "grnxx/lock.hpp"
 #include "grnxx/logger.hpp"
+#include "grnxx/mutex.hpp"
 #include "grnxx/thread.hpp"
 #include "grnxx/time/stopwatch.hpp"
 #include "grnxx/time/system_clock.hpp"
 
+namespace {
+
+grnxx::Mutex mutex(grnxx::MUTEX_UNLOCKED);
+
+void thread_routine() {
+  grnxx::Thread::sleep_for(grnxx::Duration::milliseconds(10));
+}
+
+}  // namespace
+
 int main() {
   grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL |
                            grnxx::LOGGER_ENABLE_COUT);
@@ -58,5 +70,33 @@ int main() {
   GRNXX_NOTICE() << "sleep_until(now + 10ms): elapsed [ns] = "
                  << (1000.0 * elapsed.count());
 
+  stopwatch.reset();
+  std::unique_ptr<grnxx::Thread> thread(grnxx::Thread::create(thread_routine));
+  assert(thread);
+  assert(thread->join());
+  elapsed = stopwatch.elapsed();
+  GRNXX_NOTICE() << "thread + join: elapsed [ns] = "
+                 << (1000.0 * elapsed.count());
+
+  stopwatch.reset();
+  thread.reset(grnxx::Thread::create([]() {
+    grnxx::Thread::sleep_for(grnxx::Duration::milliseconds(10));
+  }));
+  assert(thread);
+  assert(thread->join());
+  elapsed = stopwatch.elapsed();
+  GRNXX_NOTICE() << "thread + join: elapsed [ns] = "
+                 << (1000.0 * elapsed.count());
+
+  stopwatch.reset();
+  thread.reset(grnxx::Thread::create([]() {
+    grnxx::Thread::sleep_for(grnxx::Duration::milliseconds(10));
+  }));
+  assert(thread);
+  assert(thread->detach());
+  elapsed = stopwatch.elapsed();
+  GRNXX_NOTICE() << "thread + detach: elapsed [ns] = "
+                 << (1000.0 * elapsed.count());
+
   return 0;
 }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index