projects
/
libcds.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
1621e9e
)
Uses unique_ptr for Threads
author
Peizhao Ou
<peizhaoo@uci.edu>
Sat, 9 Dec 2017 18:26:55 +0000
(10:26 -0800)
committer
Peizhao Ou
<peizhaoo@uci.edu>
Sat, 9 Dec 2017 18:26:55 +0000
(10:26 -0800)
test/stress/misc/barrier_driver.cpp
patch
|
blob
|
history
test/stress/misc/deque_driver.cpp
patch
|
blob
|
history
test/stress/misc/mcslock_driver.cpp
patch
|
blob
|
history
test/stress/misc/rwlock_driver.cpp
patch
|
blob
|
history
test/stress/misc/seqlock_driver.cpp
patch
|
blob
|
history
test/stress/misc/spinlock_driver.cpp
patch
|
blob
|
history
diff --git
a/test/stress/misc/barrier_driver.cpp
b/test/stress/misc/barrier_driver.cpp
index 438d033a88798b1949ebe1d4f9525ffa4de4093c..3ffe5aec36de10dbf483b1f16d436ecd59664e80 100644
(file)
--- a/
test/stress/misc/barrier_driver.cpp
+++ b/
test/stress/misc/barrier_driver.cpp
@@
-5,6
+5,7
@@
#include <cds/sync/barrier.h>
#include <cds_test/stress_test.h>
#include <iostream>
#include <cds/sync/barrier.h>
#include <cds_test/stress_test.h>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
#include <thread>
using namespace std;
@@
-19,7
+20,7
@@
static size_t s_nBarrierPassCount = 100000000;
class BarrierTest : public cds_test::stress_fixture {
protected:
static Barrier *barrier;
class BarrierTest : public cds_test::stress_fixture {
protected:
static Barrier *barrier;
- static
in
t count;
+ static
size_
t count;
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("Misc");
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("Misc");
@@
-43,16
+44,16
@@
protected:
};
Barrier *BarrierTest::barrier;
};
Barrier *BarrierTest::barrier;
-
in
t BarrierTest::count;
+
size_
t BarrierTest::count;
TEST_F(BarrierTest, Wait) {
barrier = new Barrier(s_nBarrierThreadCount);
TEST_F(BarrierTest, Wait) {
barrier = new Barrier(s_nBarrierThreadCount);
- std::
thread *threads = new std::thread[s_nBarrierThreadCount]
;
- for (
in
t i = 0; i < s_nBarrierThreadCount; i++) {
+ std::
unique_ptr<std::thread[]> threads(new std::thread[s_nBarrierThreadCount])
;
+ for (
size_
t i = 0; i < s_nBarrierThreadCount; i++) {
threads[i] = std::thread(Thread);
}
threads[i] = std::thread(Thread);
}
- for (
in
t i = 0; i < s_nBarrierThreadCount; i++) {
+ for (
size_
t i = 0; i < s_nBarrierThreadCount; i++) {
threads[i].join();
}
}
threads[i].join();
}
}
diff --git
a/test/stress/misc/deque_driver.cpp
b/test/stress/misc/deque_driver.cpp
index e49b4a7a0e664e089f00d1de7f4bcb4f603f79d3..60809472bfffdc1b9ba7b6c06c1c76822ec36981 100644
(file)
--- a/
test/stress/misc/deque_driver.cpp
+++ b/
test/stress/misc/deque_driver.cpp
@@
-4,6
+4,7
@@
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
#include <thread>
using namespace std;
@@
-82,7
+83,8
@@
TEST_F(ChaseLevDequeTest, DequePushPopTake) {
srand(time(NULL));
// Stealer threads
srand(time(NULL));
// Stealer threads
- std::thread *threads = new std::thread[s_nDequeStealerThreadCount];
+ std::unique_ptr<std::thread[]> threads(
+ new std::thread[s_nDequeStealerThreadCount]);
for (ullong i = 0; i < s_nDequeStealerThreadCount; i++) {
threads[i] = std::thread(StealerThread, i);
}
for (ullong i = 0; i < s_nDequeStealerThreadCount; i++) {
threads[i] = std::thread(StealerThread, i);
}
diff --git
a/test/stress/misc/mcslock_driver.cpp
b/test/stress/misc/mcslock_driver.cpp
index 2a2091b93231f79b7591feb50b38b10262915b92..e37e4324ae86d9f9ed99cd3f5a0ecbf4d95743af 100644
(file)
--- a/
test/stress/misc/mcslock_driver.cpp
+++ b/
test/stress/misc/mcslock_driver.cpp
@@
-5,6
+5,7
@@
#include <cds/sync/mcs-lock.h>
#include <cds_test/stress_test.h>
#include <iostream>
#include <cds/sync/mcs-lock.h>
#include <cds_test/stress_test.h>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
#include <thread>
using namespace std;
@@
-43,11
+44,12
@@
cds_others::mcs_mutex *MCSLockTest::my_mutex;
TEST_F(MCSLockTest, BasicLockUnlock) {
my_mutex = new cds_others::mcs_mutex();
x = 0;
TEST_F(MCSLockTest, BasicLockUnlock) {
my_mutex = new cds_others::mcs_mutex();
x = 0;
- std::thread *threads = new std::thread[s_nMCSLockThreadCount];
- for (int i = 0; i < s_nMCSLockThreadCount; i++) {
+ std::unique_ptr<std::thread[]> threads(
+ new std::thread[s_nMCSLockThreadCount]);
+ for (size_t i = 0; i < s_nMCSLockThreadCount; i++) {
threads[i] = std::thread(Thread);
}
threads[i] = std::thread(Thread);
}
- for (
in
t i = 0; i < s_nMCSLockThreadCount; i++) {
+ for (
size_
t i = 0; i < s_nMCSLockThreadCount; i++) {
threads[i].join();
}
if (x != s_nMCSLockPassCount * s_nMCSLockThreadCount) {
threads[i].join();
}
if (x != s_nMCSLockPassCount * s_nMCSLockThreadCount) {
diff --git
a/test/stress/misc/rwlock_driver.cpp
b/test/stress/misc/rwlock_driver.cpp
index 2c61d440e4a75c3e563db772e35d177f98aafb95..548d16a9d95466978d3a8eea92abf0e628abc93b 100644
(file)
--- a/
test/stress/misc/rwlock_driver.cpp
+++ b/
test/stress/misc/rwlock_driver.cpp
@@
-5,6
+5,7
@@
#include <cds/sync/rwlock.h>
#include <cds_test/stress_test.h>
#include <iostream>
#include <cds/sync/rwlock.h>
#include <cds_test/stress_test.h>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
#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:
typedef cds_others::RWLock RWLock;
class RWLockTest : public cds_test::stress_fixture {
protected:
- static
in
t sum;
- static
in
t x;
+ static
size_
t sum;
+ static
size_
t x;
static RWLock *rwlock;
static void SetUpTestCase() {
static RWLock *rwlock;
static void SetUpTestCase() {
@@
-58,20
+59,20
@@
protected:
}
};
}
};
-
in
t RWLockTest::x;
-
in
t RWLockTest::sum;
+
size_
t RWLockTest::x;
+
size_
t RWLockTest::sum;
RWLock *RWLockTest::rwlock;
TEST_F(RWLockTest, BasicLockUnlock) {
rwlock = new RWLock();
RWLock *RWLockTest::rwlock;
TEST_F(RWLockTest, BasicLockUnlock) {
rwlock = new RWLock();
-
in
t num_threads = s_nRWLockThreadCount;
+
size_
t num_threads = s_nRWLockThreadCount;
for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
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 (size_t i = 0; i < num_threads; i++) {
threads[i] = std::thread(ReaderWriterThread, write_percentage);
}
- for (
in
t i = 0; i < num_threads; i++) {
+ for (
size_
t i = 0; i < num_threads; i++) {
threads[i].join();
}
}
threads[i].join();
}
}
diff --git
a/test/stress/misc/seqlock_driver.cpp
b/test/stress/misc/seqlock_driver.cpp
index abf2583701ff72198edad7a494bcf69330b48665..ba47d4a9e76c52d7031ac1e226414ec6d9003d14 100644
(file)
--- a/
test/stress/misc/seqlock_driver.cpp
+++ b/
test/stress/misc/seqlock_driver.cpp
@@
-5,6
+5,7
@@
#include <cds/sync/seqlock.h>
#include <cds_test/stress_test.h>
#include <iostream>
#include <cds/sync/seqlock.h>
#include <cds_test/stress_test.h>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
#include <thread>
using namespace std;
@@
-18,11
+19,8
@@
static size_t s_nSeqLockPassCount = 2000000;
class SeqLockTest : public cds_test::stress_fixture {
protected:
class SeqLockTest : public cds_test::stress_fixture {
protected:
- static
in
t sum;
+ static
size_
t sum;
static SeqLock *seqlock;
static SeqLock *seqlock;
- static const int kReaderThreads = 0;
- static const int kWriterThreads = 0;
- static const int kWriterPercentage = 15;
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("Misc");
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("Misc");
@@
-30,12
+28,8
@@
protected:
GetConfig(SeqLockPassCount);
}
GetConfig(SeqLockPassCount);
}
- static void ReaderThread() {}
-
- static void WriterThread() {}
-
static void ReaderWriterThread(int write_percentage) {
static void ReaderWriterThread(int write_percentage) {
- for (
in
t i = 0; i < s_nSeqLockPassCount; i++) {
+ for (
size_
t i = 0; i < s_nSeqLockPassCount; i++) {
if (rand(100) < write_percentage) {
sum += seqlock->read();
} else {
if (rand(100) < write_percentage) {
sum += seqlock->read();
} else {
@@
-45,20
+39,20
@@
protected:
}
};
}
};
-
in
t SeqLockTest::sum;
+
size_
t SeqLockTest::sum;
SeqLock *SeqLockTest::seqlock;
TEST_F(SeqLockTest, BasicReadWriter) {
seqlock = new SeqLock();
for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
SeqLock *SeqLockTest::seqlock;
TEST_F(SeqLockTest, BasicReadWriter) {
seqlock = new SeqLock();
for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
- std::thread *threads = new std::thread[s_nSeqLockReaderWriterThreadCount];
+ std::unique_ptr<std::thread[]> threads(
+ new std::thread[s_nSeqLockReaderWriterThreadCount]);
for (size_t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
threads[i] = std::thread(ReaderWriterThread, write_percentage);
}
for (size_t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
threads[i] = std::thread(ReaderWriterThread, write_percentage);
}
- for (
in
t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
+ for (
size_
t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
threads[i].join();
}
threads[i].join();
}
- delete[] threads;
}
}
}
}
diff --git
a/test/stress/misc/spinlock_driver.cpp
b/test/stress/misc/spinlock_driver.cpp
index a811db23f30279c810cd3f4d8252d0d1521c77dc..159c18af76018aa139d16a188f00ebe147b1f139 100644
(file)
--- a/
test/stress/misc/spinlock_driver.cpp
+++ b/
test/stress/misc/spinlock_driver.cpp
@@
-7,6
+7,7
@@
#include <cds_test/stress_test.h>
#include <iostream>
#include <iostream>
#include <cds_test/stress_test.h>
#include <iostream>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
#include <thread>
using namespace std;
@@
-23,7
+24,7
@@
static size_t s_nTicketLockPassCount = 4000000;
#define TASK(lock_type, lock_ptr, pass_cnt) \
static void Thread##lock_type() { \
#define TASK(lock_type, lock_ptr, pass_cnt) \
static void Thread##lock_type() { \
- for (
int i = 0; i < pass_cnt; i++) {
\
+ for (
size_t i = 0; i < pass_cnt; i++) {
\
lock_ptr->lock(); \
x++; \
lock_ptr->unlock(); \
lock_ptr->lock(); \
x++; \
lock_ptr->unlock(); \
@@
-34,21
+35,26
@@
static size_t s_nTicketLockPassCount = 4000000;
TEST_F(SpinLockTest, lock_type) { \
lock_ptr = new lock_type(); \
x = 0; \
TEST_F(SpinLockTest, lock_type) { \
lock_ptr = new lock_type(); \
x = 0; \
+ std::unique_ptr<std::thread[]>(new std::thread[s_nSpinLockThreadCount]); \
std::thread *threads = new std::thread[s_nSpinLockThreadCount]; \
std::thread *threads = new std::thread[s_nSpinLockThreadCount]; \
- for (
int i = 0; i < s_nSpinLockThreadCount; i++) {
\
+ for (
size_t i = 0; i < s_nSpinLockThreadCount; i++) {
\
threads[i] = std::thread(Thread##lock_type); \
} \
threads[i] = std::thread(Thread##lock_type); \
} \
- for (
int i = 0; i < s_nSpinLockThreadCount; i++) {
\
+ for (
size_t i = 0; i < s_nSpinLockThreadCount; i++) {
\
threads[i].join(); \
} \
if (x != s_nSpinLockThreadCount * pass_cnt) { \
cout << "Incorrect " << #lock_type << "\n"; \
threads[i].join(); \
} \
if (x != s_nSpinLockThreadCount * pass_cnt) { \
cout << "Incorrect " << #lock_type << "\n"; \
+ cout << "x=" << x << "\nThreadCount=" << s_nSpinLockThreadCount \
+ << "\nPassCount=" << pass_cnt \
+ << "\t&&\tSupposed times=" << s_nSpinLockThreadCount * pass_cnt \
+ << "\n"; \
} \
}
class SpinLockTest : public cds_test::stress_fixture {
protected:
} \
}
class SpinLockTest : public cds_test::stress_fixture {
protected:
- static
in
t x;
+ static
size_
t x;
static TicketLock *ticket_mutex;
static SpinLock *spin_mutex;
static Reentrant32 *reentrant_mutex32;
static TicketLock *ticket_mutex;
static SpinLock *spin_mutex;
static Reentrant32 *reentrant_mutex32;
@@
-67,7
+73,7
@@
protected:
TASK(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)
};
TASK(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)
};
-
in
t SpinLockTest::x;
+
size_
t SpinLockTest::x;
TicketLock *SpinLockTest::ticket_mutex;
SpinLock *SpinLockTest::spin_mutex;
Reentrant32 *SpinLockTest::reentrant_mutex32;
TicketLock *SpinLockTest::ticket_mutex;
SpinLock *SpinLockTest::spin_mutex;
Reentrant32 *SpinLockTest::reentrant_mutex32;