From 114e32af8fd5d8e04683df4073d73e0652f09fff Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Thu, 4 Aug 2016 16:00:27 -0700 Subject: [PATCH] Use std::thread rather than pthreads in AtomicHashMapTest Summary: The tests aren't dependent on it being pthread, so use standardized stuff instead. Reviewed By: yfeldblum Differential Revision: D3665698 fbshipit-source-id: ad91facb75a9c5d7a90bfa294cc98bb07629de1b --- folly/test/AtomicHashMapTest.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/folly/test/AtomicHashMapTest.cpp b/folly/test/AtomicHashMapTest.cpp index 28f57678..32ad64d0 100644 --- a/folly/test/AtomicHashMapTest.cpp +++ b/folly/test/AtomicHashMapTest.cpp @@ -441,28 +441,28 @@ void* insertThreadArr(void* jj) { } std::atomic runThreadsCreatedAllThreads; -void runThreads(void *(*thread)(void*), int numThreads, void **statuses) { +void runThreads(void *(*mainFunc)(void*), int numThreads, void **statuses) { folly::BenchmarkSuspender susp; runThreadsCreatedAllThreads.store(false); - vector threadIds; + vector threads; for (int64_t j = 0; j < numThreads; j++) { - pthread_t tid; - if (pthread_create(&tid, nullptr, thread, (void*) j) != 0) { - LOG(ERROR) << "Could not start thread"; - } else { - threadIds.push_back(tid); - } + threads.emplace_back([statuses, mainFunc, j]() { + auto ret = mainFunc((void*)j); + if (statuses != nullptr) { + statuses[j] = ret; + } + }); } susp.dismiss(); runThreadsCreatedAllThreads.store(true); - for (size_t i = 0; i < threadIds.size(); ++i) { - pthread_join(threadIds[i], statuses == nullptr ? nullptr : &statuses[i]); + for (size_t i = 0; i < threads.size(); ++i) { + threads[i].join(); } } -void runThreads(void *(*thread)(void*)) { - runThreads(thread, FLAGS_numThreads, nullptr); +void runThreads(void *(*mainFunc)(void*)) { + runThreads(mainFunc, FLAGS_numThreads, nullptr); } } @@ -680,8 +680,7 @@ void* atomicHashArrayInsertRaceThread(void* /* j */) { numInserted++; } } - pthread_exit((void *) numInserted); - folly::assume_unreachable(); + return (void*)numInserted; } TEST(Ahm, atomic_hash_array_insert_race) { AHA* arr = atomicHashArrayInsertRaceArray.get(); -- 2.34.1