#include #include #include #include int main() { std::vector vec; const int len = 34479; struct non_trivial_range : tbb::blocked_range { using non_trivial_range::blocked_range::blocked_range; ~non_trivial_range() { assert( cookie == 0xc001c001 ); cookie = 0xdeadbeef; } unsigned cookie = 0xc001c001; }; vec.assign( len, 1 ); // this works fine int s = tbb::parallel_reduce( non_trivial_range{ vec.begin(), vec.end() }, 0, [&]( const auto & rng, int acc ) { for (int p : rng) acc += p; // work is irrelevant return acc; }, std::plus<>() ); assert( s == len ); // this fails eventually for (int i = 0; i < 1000; ++i) { s = tbb::parallel_scan( non_trivial_range{ vec.begin(), vec.end() }, 0, [&]( const auto & rng, int acc, auto is_final ) { for (int p : rng) acc += p; // work is irrelevant return acc; }, std::plus<>() ); assert( s == len ); } return s; }