I'm trying to transmit the array bounds element values to the function array_sync. The code:
auto array_sync = []() noexcept {
static auto phase = bounds[i];
return phase;
phase = bounds[i+1];
};
std::barrier sync_point(bounds, on_completion);
auto array_work = [&](std::string name) {
array_transform(bounds[i + 1] * n, bounds[i + 2] * n, num_array_1, n);
sync_point.arrive_and_wait();
array_transform(bounds[i + 1] * n, bounds[i + 2] * n, num_array_1, n);
sync_point.arrive_and_wait();
};
// the cycle for threads output
for (int i = 0; i <= 6; i += 2) {
// the function for main thread
array_transform(bounds[i + 1] * n, bounds[i + 2] * n, num_array_1, n);
// new thread
threads.emplace_back(work, bounds);
}
// threads joining
for (auto& thread : threads) {
thread.join();
}
Tell me please, how to declare the function sync_point right.
If I decipher what you're trying to do correctly, then
should do what you want. The way this works is:
[&]means that it captures the surroundings by reference, so you can useboundsandiand their values change in the lambda when they do on the outside[phase=bounds[i]]gives the lambda object a named memberphasethat's initialized withbounds[i]mutablemakes it so that members of the lambda are changeable, so you can updatephasein the lambda function body.resultis introduced because the function exits atreturn, so you have to changephasebefore then.It's a bit hard to tell if this is what you want, though, because the code you showed never calls
array_sync.