19 #include <sys/types.h> 23 #include <condition_variable> 29 #include <boost/thread/tss.hpp> 30 #include <glog/logging.h> 36 using namespace folly;
43 pthread_key_create(&key_, OnThreadExit);
47 return static_cast<T*
>(pthread_getspecific(key_));
52 pthread_setspecific(key_, t);
55 delete static_cast<T*
>(obj);
62 DEFINE_int32(numThreads, 8,
"Number simultaneous threads for benchmarks.");
65 BENCHMARK(FB_CONCATENATE(BM_mt_, var), iters) { \ 66 const int itersPerThread = iters / FLAGS_numThreads; \ 67 std::vector<std::thread> threads; \ 68 for (int i = 0; i < FLAGS_numThreads; ++i) { \ 69 threads.push_back(std::thread([&]() { \ 70 var.reset(new int(0)); \ 71 for (int j = 0; j < itersPerThread; ++j) { \ 76 for (auto& t : threads) { \ 84 REG(pthread_get_specific)
94 template <
typename TL>
96 const int itersPerThread = iters / FLAGS_numThreads;
97 std::vector<std::thread>
threads;
99 for (
int i = 0;
i < FLAGS_numThreads; ++
i) {
100 threads.push_back(std::thread([&]() {
102 for (
int j = 0; j < itersPerThread; ++j) {
104 var.get()->b += var.get()->a;
106 var.get()->b += var.get()->a;
110 for (
auto&
t : threads) {
116 run_multi<ThreadLocalPtr<foo>>(iters);
119 run_multi<PThreadGetSpecific<foo>>(iters);
122 run_multi<boost::thread_specific_ptr<foo>>(iters);
127 gflags::ParseCommandLineFlags(&argc, &argv,
true);
128 gflags::SetCommandLineOptionWithMode(
129 "bm_max_iters",
"100000000", gflags::SET_FLAG_IF_DEFAULT);
ThreadLocalPtr< int > tlp
int main(int argc, char **argv)
—— Concurrent Priority Queue Implementation ——
static void OnThreadExit(void *obj)
std::vector< std::thread::id > threads
boost::thread_specific_ptr< int > boost_tsp
DEFINE_int32(numThreads, 8,"Number simultaneous threads for benchmarks.")
void run_multi(uint32_t iters)
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
PThreadGetSpecific< int > pthread_get_specific