Commit 114e32af authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 7

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
parent 5beef6c2
...@@ -441,28 +441,28 @@ void* insertThreadArr(void* jj) { ...@@ -441,28 +441,28 @@ void* insertThreadArr(void* jj) {
} }
std::atomic<bool> runThreadsCreatedAllThreads; std::atomic<bool> runThreadsCreatedAllThreads;
void runThreads(void *(*thread)(void*), int numThreads, void **statuses) { void runThreads(void *(*mainFunc)(void*), int numThreads, void **statuses) {
folly::BenchmarkSuspender susp; folly::BenchmarkSuspender susp;
runThreadsCreatedAllThreads.store(false); runThreadsCreatedAllThreads.store(false);
vector<pthread_t> threadIds; vector<std::thread> threads;
for (int64_t j = 0; j < numThreads; j++) { for (int64_t j = 0; j < numThreads; j++) {
pthread_t tid; threads.emplace_back([statuses, mainFunc, j]() {
if (pthread_create(&tid, nullptr, thread, (void*) j) != 0) { auto ret = mainFunc((void*)j);
LOG(ERROR) << "Could not start thread"; if (statuses != nullptr) {
} else { statuses[j] = ret;
threadIds.push_back(tid);
} }
});
} }
susp.dismiss(); susp.dismiss();
runThreadsCreatedAllThreads.store(true); runThreadsCreatedAllThreads.store(true);
for (size_t i = 0; i < threadIds.size(); ++i) { for (size_t i = 0; i < threads.size(); ++i) {
pthread_join(threadIds[i], statuses == nullptr ? nullptr : &statuses[i]); threads[i].join();
} }
} }
void runThreads(void *(*thread)(void*)) { void runThreads(void *(*mainFunc)(void*)) {
runThreads(thread, FLAGS_numThreads, nullptr); runThreads(mainFunc, FLAGS_numThreads, nullptr);
} }
} }
...@@ -680,8 +680,7 @@ void* atomicHashArrayInsertRaceThread(void* /* j */) { ...@@ -680,8 +680,7 @@ void* atomicHashArrayInsertRaceThread(void* /* j */) {
numInserted++; numInserted++;
} }
} }
pthread_exit((void *) numInserted); return (void*)numInserted;
folly::assume_unreachable();
} }
TEST(Ahm, atomic_hash_array_insert_race) { TEST(Ahm, atomic_hash_array_insert_race) {
AHA* arr = atomicHashArrayInsertRaceArray.get(); AHA* arr = atomicHashArrayInsertRaceArray.get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment