#include <folly/Benchmark.h>
#include <folly/ThreadLocal.h>
#include <condition_variable>
#include <mutex>
#include <thread>
Go to the source code of this file.
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
void runTest |
( |
int |
iters, |
|
|
int |
numThreads |
|
) |
| |
Definition at line 42 of file ThreadLocalAccessBenchmark.cpp.
References folly::BENCHMARK_DRAW_LINE(), BENCHMARK_PARAM, folly::BenchmarkSuspender::dismiss(), i, m, mutex, folly::BenchmarkSuspender::rehire(), folly::pushmi::detail::t, and threads.
45 std::vector<SimpleThreadCachedInt> stci(numThreads);
48 std::condition_variable cv, cvw;
52 std::vector<std::thread>
threads;
53 for (
int i = 0;
i < numThreads;
i++) {
54 threads.push_back(std::thread([
i,
62 &numRunning]()
mutable {
69 std::lock_guard<std::mutex> lk(m);
70 if (++numRunning == numThreads) {
81 std::unique_lock<std::mutex> lk(mw);
82 cvw.wait(lk, [&]() {
return !running; });
89 std::unique_lock<std::mutex> lk(m);
90 cv.wait(lk, [&]() {
return numRunning == numThreads; });
96 for (
int i = 0;
i < iters;
i++) {
97 stci[
i % numThreads].access();
103 std::lock_guard<std::mutex> lk(mw);
109 for (
auto&
t : threads) {
std::vector< std::thread::id > threads
static map< string, int > m