#include #include #include #include // Sharing without race. int main(int argc, char *argv[]) { if (argc != 3) { std::cerr << "Please, give two integer values in the command line.\n"; return 1; } auto a = std::stoi(argv[1]); auto b = std::stoi(argv[2]); int max, min; std::thread calc_min([&min, a, b]() { if (a < b) { min = a; } else { min = b; } }); std::thread calc_max([&max, a, b]() { if (a > b) { max = a; } else { max = b; } }); calc_min.join(); calc_max.join(); std::cout << "Largest is " << max << ", smallest is " << min << std::endl; return 0; }