Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include "stdafx.h"
- #include "iostream"
- #include <thread>
- #include <cmath>
- #include <vector>
- using namespace std;
- bool PrimeNumberChecker(int x);
- void PrimeIterator(int x, int y);
- static const int num_threads = 99;
- int main()
- {
- int val1, dividend, divisor, threadIterator1, threadIterator2;
- int x, y, i;
- thread t[num_threads];
- cout << "Enter Start Boundary: ";
- cin >> x;
- cout << "nEnter End Boundary: ";
- cin >> y;
- val1 = (y - x) / 100;
- dividend = floor(val1);
- divisor = fmod(y-x, 100);
- if (y-x >= 100)
- {
- thread t2(PrimeIterator, x, divisor);
- for (i = 1; i <= num_threads; i++)
- {
- threadIterator1 = dividend * i;
- threadIterator2 = dividend * (i + 1);
- t[i] = thread(PrimeIterator, threadIterator1, threadIterator2, i);
- }
- t2.join();
- for (int i = 0; i < num_threads; ++i) {
- t[i].join();
- }
- }
- system("pause");
- return 0;
- }
- bool PrimeNumberChecker(int x)
- {
- int i, t;
- for (i = 2; i <= x ; i++)
- {
- for (t = 2; t <= x; t++)
- {
- if (i*t == x)
- {
- return false;
- }
- }
- }
- return true;
- }
- void PrimeIterator(int startBoundary, int endBoundary)
- {
- int i;
- for (i = startBoundary; i <= endBoundary; i++)
- {
- if (PrimeNumberChecker(i))
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement