Search code examples
c++c++11g++tbblinker-errors

Error while linking with tbb::task_arena and tbb::task_scheduler_observer


I want to hook into a tbb::task_arena by using a tbb::task_scheduler_observer. According to the documentation this should work like shown here. However, when I'm trying to compile the following code

#define TBB_PREVIEW_TASK_ARENA 1
#include "tbb/task_scheduler_observer.h"
#include "tbb/task.h"
#include "tbb/task_arena.h"
class MyObserver : public tbb::task_scheduler_observer
{
  public:
    MyObserver( tbb::task_arena &a ) : tbb::task_scheduler_observer(a)
    {
       observe(true); // activate the observer
    }
    /*override*/ void on_scheduler_entry( bool worker ) 
    {
      // Do something here
    }
    /*override*/ void on_scheduler_exit( bool worker ) { }
};

and

#define TBB_PREVIEW_TASK_ARENA 1
#include "tbb/task_arena.h"

int main()
{
  tbb::task_arena a;
  MyObserver my(a);
}

I get an

undefined refference to `tbb::task_arena::internal_terminate()`

error. Other tbb functions (and classes) are working fine when compiled with the -ltbb flag.

I use Ubuntu 14.04 and g++ 4.8.4 with -std=c++11 enabled.


Solution

  • Answering my own question, here's what solved the problem. Apparently the task_scheduler_observer that takes a tbb::task_arena is a Community Preview feature. You need to enable it before including the header

    #define TBB_PREVIEW_LOCAL_OBSERVER 1
    #include "tbb/task_scheduler_observer.h"
    

    will do the trick. Now it compiles fine. Additionally, I build the library from source instead of using the one provided in the ubuntu repositories. There's a CMake build available here