30#include <condition_variable>
59 constexpr int number(
const Defaults rhs)
noexcept {
60 return static_cast<int>(rhs);
64 int array[array_size] = { 0 };
66 std::condition_variable cvRead;
67 std::condition_variable cvWrite;
69 void reset(
int v1,
int array_value) {
70 std::unique_lock<std::mutex> lock(mtx_value);
72 for(
int & i : array) {
77 void putThreadType01(
int _len,
int startValue) {
78 const int len =
std::min(number(array_size), _len);
80 std::unique_lock<std::mutex> lock(mtx_value);
81 for(
int i=0; i<len; i++) {
82 array[i] = startValue+i;
88 void getThreadType01(
const std::string& msg,
int _len,
int startValue) {
89 const int len =
std::min(number(array_size), _len);
91 std::unique_lock<std::mutex> lock(mtx_value);
92 while( startValue != value1 ) {
95 REQUIRE_MSG(msg+
": %s: value at read value1 (start)", startValue == value1);
97 for(
int i=0; i<len; i++) {
103 void putThreadType11(
int indexAndValue) {
104 const int idx =
std::min(number(array_size)-1, indexAndValue);
109 std::unique_lock<std::mutex> lock(mtx_value);
111 while( idx != (value1 * -1) - 1 ) {
120 void getThreadType11(
const std::string& msg,
int _idx) {
121 const int idx =
std::min(number(array_size)-1, _idx);
127 std::unique_lock<std::mutex> lock(mtx_value);
128 while( idx != value1 ) {
135 int next_idx = (idx+1)%array_size;
136 next_idx = ( next_idx + 1 ) * -1;
139 cvWrite.notify_all();
149 INFO_STR(
"\n\ntest01_Read1Write1.a\n");
152 std::thread getThread01(&TestMemModelSCDRF01::getThreadType01,
this,
"test01.get01", array_size, 3);
153 std::thread putThread01(&TestMemModelSCDRF01::putThreadType01,
this, array_size, 3);
159 INFO_STR(
"\n\ntest01_Read2Write1.a\n");
162 std::thread getThread00(&TestMemModelSCDRF01::getThreadType01,
this,
"test01.get00", array_size, 4);
163 std::thread getThread01(&TestMemModelSCDRF01::getThreadType01,
this,
"test01.get01", array_size, 4);
164 std::thread putThread01(&TestMemModelSCDRF01::putThreadType01,
this, array_size, 4);
170 INFO_STR(
"\n\ntest01_Read2Write1.b\n");
173 std::thread putThread01(&TestMemModelSCDRF01::putThreadType01,
this, array_size, 5);
174 std::thread getThread00(&TestMemModelSCDRF01::getThreadType01,
this,
"test01.get00", array_size, 5);
175 std::thread getThread01(&TestMemModelSCDRF01::getThreadType01,
this,
"test01.get01", array_size, 5);
183 INFO_STR(
"\n\ntest02_Read4Write1\n");
186 std::thread getThread01(&TestMemModelSCDRF01::getThreadType01,
this,
"test02.get01", array_size, 6);
187 std::thread getThread02(&TestMemModelSCDRF01::getThreadType01,
this,
"test02.get02", array_size, 6);
188 std::thread putThread01(&TestMemModelSCDRF01::putThreadType01,
this, array_size, 6);
189 std::thread getThread03(&TestMemModelSCDRF01::getThreadType01,
this,
"test02.get03", array_size, 6);
190 std::thread getThread04(&TestMemModelSCDRF01::getThreadType01,
this,
"test02.get04", array_size, 6);
199 INFO_STR(
"\n\ntest11_Read10Write10\n");
202 std::thread reader[array_size];
203 std::thread writer[array_size];
204 for(
int i=0; i<number(array_size); i++) {
205 reader[i] = std::thread(&TestMemModelSCDRF01::getThreadType11,
this,
"test11.get11", i);
207 for(
int i=0; i<number(array_size); i++) {
208 writer[i] = std::thread(&TestMemModelSCDRF01::putThreadType11,
this, i);
210 for(
int i=0; i<number(array_size); i++) {
213 for(
int i=0; i<number(array_size); i++) {
219 INFO_STR(
"\n\ntest12_Read10Write10\n");
222 std::thread reader[array_size];
223 std::thread writer[array_size];
224 for(
int i=0; i<number(array_size); i++) {
225 writer[i] = std::thread(&TestMemModelSCDRF01::putThreadType11,
this, i);
227 for(
int i=0; i<number(array_size); i++) {
228 reader[i] = std::thread(&TestMemModelSCDRF01::getThreadType11,
this,
"test12.get11", i);
230 for(
int i=0; i<number(array_size); i++) {
233 for(
int i=0; i<number(array_size); i++) {
#define REQUIRE_MSG(MSG,...)
test_mm_sc_drf_01: Testing SC-DRF non-atomic global read and write within a locked mutex critical blo...
void test12_Read10Write10()
void test03_Read4Write1()
void test01_Read1Write1()
void test11_Read10Write10()
void test02_Read2Write1()
std::string to_string(const alphabet &v) noexcept
constexpr T min(const T x, const T y) noexcept
Returns the minimum of two integrals (w/ branching) in O(1)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
METHOD_AS_TEST_CASE(TestMemModelSCDRF01::test_list, "Test TestMemModelSCDRF 01- test_list")