Commit d3dbb70d authored by captainwong's avatar captainwong

testing atomic

parent 9a769384
...@@ -9,7 +9,7 @@ void test() ...@@ -9,7 +9,7 @@ void test()
using namespace std; using namespace std;
using namespace std::chrono; using namespace std::chrono;
uint32_t count = 0; uintmax_t count = 0;
while (true) { while (true) {
atomic_int x(0), y(0); atomic_int x(0), y(0);
int r1 = 0, r2 = 0; int r1 = 0, r2 = 0;
...@@ -30,14 +30,14 @@ void test() ...@@ -30,14 +30,14 @@ void test()
t2.join(); t2.join();
count++; count++;
printf("\r%zd", count); printf("%lld\r", count);
if (r1 == 42 && r2 == 42) { if (r1 == 42 && r2 == 42) {
printf("\n"); printf("\n");
break; break;
} }
} }
printf("after %d times trying, r1,r2 are finally 42!\n", count); printf("after %lld times trying, r1,r2 are finally 42!\n", count);
} }
int main() int main()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment