25 auto generator = tpf::chrono_random::random_generator<int>(0, (
int)
count);
27 std::vector<int> v; v.reserve(
count);
31 for(
size_t i=0; i <
count; ++i)
32 v.emplace_back(generator());
42 std::for_each(std::execution::par_unseq, v.begin(), v.end(),
43 [&generator, &
mutex](
auto& e)
48 std::lock_guard<std::mutex> lock(mutex);
61 auto generator = tpf::chrono_random::random_generator<int>(0, (
int)
count);
63 std::vector<int> v; v.reserve(
count);
67 for(
size_t i=0; i <
count; ++i)
68 v.emplace_back(generator());
75 std::atomic<bool> operation_success{
true};
78 std::for_each(std::execution::par_unseq, v.begin(), v.end(),
79 [&generator, &operation_success, &
mutex](
auto& e)
85 std::unique_lock<std::mutex> lock(mutex);
92 operation_success = false;
105 auto generator = tpf::chrono_random::random_generator<int>(0, (
int)
count);
107 std::vector<int> v; v.reserve(
count);
111 for(
size_t i=0; i <
count; ++i)
112 v.emplace_back(generator());
120 std::exception_ptr exception_ptr{
nullptr};
126 std::for_each(std::execution::par_unseq, v.begin(), v.end(),
127 [&generator, &exception_ptr, &
mutex](
auto& e)
131 std::unique_lock<std::mutex> lock(mutex);
132 auto d = generator();
134 if(exception_ptr==nullptr)
138 e = tpf::safe_type::safe_div(e, d);
143 std::lock_guard<std::mutex> lock(mutex);
144 exception_ptr = std::current_exception();
148 if(exception_ptr==
nullptr)
152 std::rethrow_exception(exception_ptr);
165 catch(
const std::exception& e)
170 stream <<
"Now, our parallel algorithm works even if exception is thrown" <<
endl;
void safer_way_of_parallel_algorithm_using_exception()
void problem_with_parallel_algorithm()
void safer_way_of_parallel_algorithm()
Stream output operators << are implemented.
This file implements safe arithmetic.