MCPcopy Create free account
hub / github.com/Compaile/ctrack / main

Function main

examples/multithreaded_prime_counter.cpp:28–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28int main() {
29 const int totalNumbers = 1000000;
30 const int threadCount = 8;
31 const int numbersPerThread = totalNumbers / threadCount;
32
33 std::vector<std::thread> threads;
34
35 for (int i = 0; i < threadCount; ++i) {
36 int start = i * numbersPerThread + 1;
37 int end = (i == threadCount - 1) ? totalNumbers : (i + 1) * numbersPerThread;
38 threads.emplace_back(countPrimesInRange, start, end);
39 }
40
41 for (auto& thread : threads) {
42 thread.join();
43 }
44
45 std::cout << "Total primes found: " << primeCount << std::endl;
46
47 ctrack::result_print();
48
49 return 0;
50}

Callers

nothing calls this directly

Calls 1

result_printFunction · 0.85

Tested by

no test coverage detected