3 and 4
unknown
c_cpp
8 months ago
875 B
6
Indexable
3:
#include <iostream>
#include <thread>
int main() {
std::cout << std:: thread::hardware_concurrency() << "\n";
return 0;
}
4:
#include <iostream>
#include <thread>
void addSeven(long x, long* result) {
*result = x + 7;
}
void addTwoNumbers(long x, long y, long* sum) {
*sum = x + y;
}
void addThreeNumbers(long x, long y, long z, long* sum) {
*sum = x + y + z;
}
int main() {
long a = 10;
long b = 15, c = 20;
long x = 2, y = 5, z = 30;
long result1, result2, result3;
std::thread th1(addSeven, a, &result1);
std::thread th2(addTwoNumbers, b, c, &result2);
std::thread th3(addThreeNumbers, x, y, z, &result3);
th1.join();
th2.join();
th3.join();
std::cout << result1 << " " << result2 << " " << result3 << "\n";
return 0;
}
Editor is loading...
Leave a Comment