Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Extending task class in tbb

Adarsh_Y_
Beginner
223 Views

I am trying to extend the task class and override the "spawn_and_wait_for_all" class function. Like this.

MyTask.h:

namespace tbb {

     class my_task: public task {

      public:

               void spawn_and_wait_for_all ( task& child ) { }

     }

}

If the define the "spawn_and_wait_for_all" in the class itself (like above) I am able to call that function. But when I put the function definition in a separate cpp file I get an "undefined reference error". Like this

MyTask.h:

namespace tbb {

     class my_task: public task {

      public:

               void spawn_and_wait_for_all ( task& child );

     }

}

MyTask.cpp:

namespace tbb {

     void my_task::spawn_and_wait_for_all ( task& child ) { }

}

ERROR: undefined reference to `tbb::my_task::spawn_and_wait_for_all (tbb::task&)'

Am I doing anything fundamentally wrong here? I have even tried not extending the task class but add a new "new_spawn_and_wait_for_all" function to the task class itself and defining it in task.cpp. It still gives me an undefined reference error.

0 Kudos
1 Reply
RafSchietekat
Valued Contributor III
223 Views

Don't change TBB itself: just define the class in your own library and your own namespace.

Don't try to override a non-virtual member function.

I'm guessing that your definition was not appropriately scoped, so the compiler made it into a new unrelated function.

0 Kudos
Reply