MCPcopy Create free account
hub / github.com/Snapchat/Valdi / runParallel

Function runParallel

valdi/test/utils/valdi_test_utils.cpp:308–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308void runParallel(size_t threadsCount, int64_t durationSeconds, DispatchFunction run) {
309 if (threadsCount > 1) {
310 std::vector<Ref<Thread>> threads;
311 std::atomic_bool cont = true;
312
313 for (size_t i = 0; i < 8; i++) {
314 auto thread = Thread::create(STRING_LITERAL("Worker Thread"), ThreadQoSClassMax, [&]() {
315 while (cont) {
316 run();
317 }
318 });
319
320 SC_ASSERT(thread);
321
322 threads.emplace_back(thread.value());
323 }
324
325 std::this_thread::sleep_for(std::chrono::seconds(durationSeconds));
326
327 cont = false;
328
329 for (const auto& thread : threads) {
330 thread->join();
331 }
332 } else {
333 snap::utils::time::StopWatch sw;
334 sw.start();
335
336 while (sw.elapsedSeconds() < durationSeconds) {
337 run();
338 }
339 }
340}
341
342bool runTypeScriptTests(std::string_view modulePath,
343 Valdi::IJavaScriptBridge* jsBridge,

Callers

nothing calls this directly

Calls 6

valueMethod · 0.65
startMethod · 0.65
createFunction · 0.50
runFunction · 0.50
joinMethod · 0.45
elapsedSecondsMethod · 0.45

Tested by

no test coverage detected