Repository: mesos
Updated Branches:
  refs/heads/master 8727301d3 -> 2b952a76b


Used std::thread instead of pthread for cgroups tests.

Review: https://reviews.apache.org/r/36823


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cbc102ed
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cbc102ed
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cbc102ed

Branch: refs/heads/master
Commit: cbc102ed6379d71f0386eba1b82dd75bbaa146da
Parents: 8727301
Author: Joris Van Remoortere <[email protected]>
Authored: Wed Jul 29 15:54:47 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Wed Jul 29 16:19:24 2015 -0700

----------------------------------------------------------------------
 src/tests/containerizer/cgroups_tests.cpp | 37 +++++++++++++-------------
 1 file changed, 18 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cbc102ed/src/tests/containerizer/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cgroups_tests.cpp 
b/src/tests/containerizer/cgroups_tests.cpp
index caecd5d..ea54ab8 100644
--- a/src/tests/containerizer/cgroups_tests.cpp
+++ b/src/tests/containerizer/cgroups_tests.cpp
@@ -26,6 +26,7 @@
 
 #include <set>
 #include <string>
+#include <thread>
 #include <vector>
 
 #include <sys/mman.h>
@@ -36,6 +37,7 @@
 #include <gmock/gmock.h>
 
 #include <process/gtest.hpp>
+#include <process/latch.hpp>
 #include <process/owned.hpp>
 
 #include <stout/gtest.hpp>
@@ -798,26 +800,20 @@ TEST_F(CgroupsAnyHierarchyWithFreezerTest, 
ROOT_CGROUPS_Destroy)
 }
 
 
-void* threadFunction(void*)
-{
-  // Newly created threads have PTHREAD_CANCEL_ENABLE and
-  // PTHREAD_CANCEL_DEFERRED so they can be cancelled from the main thread.
-  while (true) { sleep(1); }
-
-  return NULL;
-}
-
-
 TEST_F(CgroupsAnyHierarchyWithFreezerTest, ROOT_CGROUPS_AssignThreads)
 {
-  size_t numThreads = 5;
+  const size_t numThreads = 5;
 
-  pthread_t pthreads[numThreads];
+  std::thread* runningThreads[numThreads];
+
+  Latch* latch = new Latch();
 
   // Create additional threads.
-  for (size_t i = 0; i < numThreads; i++)
-  {
-    EXPECT_EQ(0, pthread_create(&pthreads[i], NULL, threadFunction, NULL));
+  for (size_t i = 0; i < numThreads; i++) {
+    runningThreads[i] = new std::thread([=]() {
+      // Wait until the main thread tells us to exit.
+      latch->await();
+    });
   }
 
   std::string hierarchy = path::join(baseHierarchy, "freezer");
@@ -843,12 +839,15 @@ TEST_F(CgroupsAnyHierarchyWithFreezerTest, 
ROOT_CGROUPS_AssignThreads)
   EXPECT_SOME_EQ(threads.get(), cgroupThreads);
 
   // Terminate the additional threads.
-  for (size_t i = 0; i < numThreads; i++)
-  {
-    EXPECT_EQ(0, pthread_cancel(pthreads[i]));
-    EXPECT_EQ(0, pthread_join(pthreads[i], NULL));
+  latch->trigger();
+
+  for (size_t i = 0; i < numThreads; i++) {
+    runningThreads[i]->join();
+    delete runningThreads[i];
   }
 
+  delete latch;
+
   // Move ourselves to the root cgroup.
   CHECK_SOME(cgroups::assign(hierarchy, "", ::getpid()));
 

Reply via email to