Uses unique_ptr for Threads
[libcds.git] / test / stress / misc / rwlock_driver.cpp
index 2c61d440e4a75c3e563db772e35d177f98aafb95..548d16a9d95466978d3a8eea92abf0e628abc93b 100644 (file)
@@ -5,6 +5,7 @@
 #include <cds/sync/rwlock.h>
 #include <cds_test/stress_test.h>
 #include <iostream>
+#include <memory>
 #include <thread>
 
 using namespace std;
@@ -17,8 +18,8 @@ static size_t s_nRWLockPassCount = 200000;
 typedef cds_others::RWLock RWLock;
 class RWLockTest : public cds_test::stress_fixture {
 protected:
-  static int sum;
-  static int x;
+  static size_t sum;
+  static size_t x;
   static RWLock *rwlock;
 
   static void SetUpTestCase() {
@@ -58,20 +59,20 @@ protected:
   }
 };
 
-int RWLockTest::x;
-int RWLockTest::sum;
+size_t RWLockTest::x;
+size_t RWLockTest::sum;
 RWLock *RWLockTest::rwlock;
 
 TEST_F(RWLockTest, BasicLockUnlock) {
   rwlock = new RWLock();
-  int num_threads = s_nRWLockThreadCount;
+  size_t num_threads = s_nRWLockThreadCount;
   for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
-    std::thread *threads = new std::thread[num_threads];
+    std::unique_ptr<std::thread[]> threads(new std::thread[num_threads]);
     for (size_t i = 0; i < num_threads; i++) {
       threads[i] = std::thread(ReaderWriterThread, write_percentage);
     }
 
-    for (int i = 0; i < num_threads; i++) {
+    for (size_t i = 0; i < num_threads; i++) {
       threads[i].join();
     }
   }