X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=test%2Fstress%2Fmisc%2Fmcslock_driver.cpp;h=2a2091b93231f79b7591feb50b38b10262915b92;hp=e2b6de9aa36fcdc509419ae089eab0990157fbc0;hb=1621e9e488395f489590c3fc497c28382fb17fd1;hpb=df58fae11f80f03ca5b50c800f2978b1ff08efea;ds=inline diff --git a/test/stress/misc/mcslock_driver.cpp b/test/stress/misc/mcslock_driver.cpp index e2b6de9a..2a2091b9 100644 --- a/test/stress/misc/mcslock_driver.cpp +++ b/test/stress/misc/mcslock_driver.cpp @@ -1,3 +1,4 @@ +#include "common.h" #include #include #include @@ -10,43 +11,48 @@ using namespace std; namespace { +static size_t s_nMCSLockThreadCount = 6; +static size_t s_nMCSLockPassCount = 3000000; + class MCSLockTest : public cds_test::stress_fixture { protected: - static int x; + static ullong x; static cds_others::mcs_mutex *my_mutex; - static const int kThreads = 6; - static void SetUpTestCase() {} + static void SetUpTestCase() { + cds_test::config const &cfg = get_config("Misc"); + GetConfig(MCSLockPassCount); + GetConfig(MCSLockThreadCount); + } static void Thread() { cds_others::mcs_mutex::guard g(my_mutex); - x = 1; my_mutex->unlock(&g); - for (int i = 0; i < 10000; i++) { - for (int j = 0; j < 300; j++) { - my_mutex->lock(&g); - x = i + j; - my_mutex->unlock(&g); - } + for (ullong i = 0; i < s_nMCSLockPassCount; i++) { + my_mutex->lock(&g); + x++; + my_mutex->unlock(&g); } my_mutex->lock(&g); } }; -int MCSLockTest::x; +ullong MCSLockTest::x; cds_others::mcs_mutex *MCSLockTest::my_mutex; -const int MCSLockTest::kThreads; TEST_F(MCSLockTest, BasicLockUnlock) { my_mutex = new cds_others::mcs_mutex(); - std::thread threads[kThreads]; - for (int i = 0; i < kThreads; i++) { + x = 0; + std::thread *threads = new std::thread[s_nMCSLockThreadCount]; + for (int i = 0; i < s_nMCSLockThreadCount; i++) { threads[i] = std::thread(Thread); } - - for (int i = 0; i < kThreads; i++) { + for (int i = 0; i < s_nMCSLockThreadCount; i++) { threads[i].join(); } + if (x != s_nMCSLockPassCount * s_nMCSLockThreadCount) { + cout << "MCS lock incorrect\n"; + } } } // namespace