in kernel/parallel-test.cpp [52:94]
const bool testAtomicPerf() {
const int count = 100000;
{
const blambda l = []() -> const bool {
inci = inci + 1;
return true;
};
cout << "Non-atomic inc test " << time(l, 1000, count) << " ms" << endl;
assert(inci == count + 1000);
}
#ifdef WANT_THREADS
{
const blambda l = []() -> const bool {
__sync_add_and_fetch(&addi, 1);
return true;
};
cout << "Atomic inc test " << time(l, 1000, count) << " ms" << endl;
assert(addi == count + 1000);
}
{
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, NULL);
const blambda l = [&mutex]() -> const bool {
pthread_mutex_lock(&mutex);
muxi = muxi + 1;
pthread_mutex_unlock(&mutex);
return true;
};
cout << "Locked inc test " << time(l, 1000, count) << " ms" << endl;
assert(muxi == count + 1000);
pthread_mutex_destroy(&mutex);
}
#endif
{
const blambda l = []() -> const bool {
*tlsi = *tlsi + 1;
return true;
};
cout << "Thread local inc test " << time(l, 1000, count) << " ms" << endl;
assert(*tlsi == count + 1000);
}
return true;
}