4444
4545#include < sys/stat.h>
4646
47- #include < cstdio >
47+ #include < iostream >
4848#include < thread>
4949#include < vector>
5050
@@ -59,22 +59,17 @@ void test_float_scalar_xchg() {
5959 std::vector<std::thread> pool;
6060
6161 for (int model : atomic_exchange_models) {
62- T afloat = 0 ;
63- T ffloat = 0 ;
62+ T afloat = 0 , ffloat = 0 ;
6463 for (int n = 0 ; n < kThreads ; ++n)
6564 pool.emplace_back (looper_numeric_xchg_atomic<T>, &afloat, model);
6665 for (int n = 0 ; n < kThreads ; ++n)
6766 pool[n].join ();
6867 pool.clear ();
6968 for (int n = 0 ; n < kThreads ; ++n)
70- pool.emplace_back (looper_numeric_xchg_nonatomic<T>, std::ref (ffloat),
71- model);
69+ pool.emplace_back (looper_numeric_xchg_nonatomic<T>, &ffloat, model);
7270 for (int n = 0 ; n < kThreads ; ++n)
7371 pool[n].join ();
7472 pool.clear ();
75- std::cout << " SCALAR (FETCH ADD): "
76- << " atomic: " << afloat << " "
77- << " nonatomic: " << ffloat << " \n " ;
7873 if (lt (afloat, ffloat) || afloat < expected * (1 - kEpsilon ) ||
7974 afloat > expected * (1 + kEpsilon ))
8075 fail ();
@@ -90,17 +85,13 @@ void test_float_scalar_cmpxchg() {
9085
9186 for (int success_model : atomic_compare_exchange_models) {
9287 for (int fail_model : atomic_compare_exchange_models) {
93- T afloat = 0 ;
94- T ffloat = 0 ;
88+ T afloat = 0 , ffloat = 0 ;
9589 for (int n = 0 ; n < kThreads ; ++n)
96- pool.emplace_back (looper_numeric_cmpxchg<T>, &afloat, std::ref ( ffloat) ,
90+ pool.emplace_back (looper_numeric_cmpxchg<T>, &afloat, & ffloat,
9791 success_model, fail_model);
9892 for (int n = 0 ; n < kThreads ; ++n)
9993 pool[n].join ();
10094 pool.clear ();
101- std::cout << " SCALAR (FETCH ADD): "
102- << " atomic: " << afloat << " "
103- << " nonatomic: " << ffloat << " \n " ;
10495 if (lt (afloat, ffloat) || afloat < expected * (1 - kEpsilon ) ||
10596 afloat > expected * (1 + kEpsilon ))
10697 fail ();
@@ -109,19 +100,19 @@ void test_float_scalar_cmpxchg() {
109100}
110101
111102void test_floating_point () {
112- printf ( " Testing float\n " ) ;
103+ std::cout << " Testing float\n " ;
113104 test_float_scalar_xchg<float >();
114105 test_float_scalar_cmpxchg<float >();
115106
116- printf ( " Testing double\n " ) ;
107+ std::cout << " Testing double\n " ;
117108 test_float_scalar_xchg<double >();
118109 test_float_scalar_cmpxchg<double >();
119110}
120111
121112int main () {
122- printf ( " %d threads; %d iterations each; total of %d \n " , kThreads , kIterations ,
123- kExpected );
124-
113+ std::cout << kThreads << " threads; "
114+ << kIterations << " iterations each; total of "
115+ << kExpected << " \n " ;
125116 test_floating_point ();
126- printf ( " PASSED\n " ) ;
117+ std::cout << " PASSED\n " ;
127118}
0 commit comments