#ifdef __has_include #if __has_include() #include #include #include using namespace std::chrono_literals; void function(int id) { for (int i = 0; i < 3; ++i) { std::cout << id << ": hello!\n"; // std::this_thread::yield(); // does it work? std::this_thread::sleep_for(250ms); } } struct object { int id; object(int id): id(id) {} void operator()() const { for (int i = 0; i < 3; ++i) { std::cout << id << ": hello!\n"; // std::this_thread::yield(); // does it work? std::this_thread::sleep_for(250ms); } } }; void test1() { tbb::parallel_invoke([] { function(1); }, object(2)); } void test2() { tbb::task_group group; group.run([] { function(1); }); // spawn 1st task and return group.run(object(2)); // spawn 2st task and return group.wait(); // wait for tasks to complete } void test3() { tbb::task_arena arena(2); // create arena with 2 threads arena.execute([] { test1(); }); // spawn task in arena } int main() { test1(); std::cout << "---------------------\n"; test2(); std::cout << "---------------------\n"; test3(); } #else #warning "Deberías instalar TBB!!!" int main() {} #endif // __has_include #endif // __has_include()