2

Imagine, I have a class MyClass and want to implement multi-threading with Intel TBB:

class MyClass
{
public:
   tbb::flow::function_node<int, double>* _fnode;
private:
   tbb::flow::graph* _graph;
   double fbody(int inp);
}

Is it possible to initialize _fnode with class-member function? Simple way does not work:

_fnode = new tbb::flow::function_node<int, double>(*_graph,1,MyClass::fbody)
Jimmy_st
  • 61
  • 1
  • 10
  • 1
    Use bind. Example from related page: function_node* pSubtracter2 = new function_node(m_graph, m_concurrency, bind(&IHelloTool::addToIt, clonedPrivate, _1)); http://atlas-computing.web.cern.ch/atlas-computing/links/buildDirectory/AtlasOffline/19.2.2/InstallArea/doc/TBBExamples/html/classHelloGraphAlg.html The function MyClass::fbody needs to be called on an instance of MyClass. You need to bind the instance with the member function. – Jonathan Oct 27 '15 at 14:39
  • Jonathan, thank You, this solution really works! :) If you don't mind, I put in question – Jimmy_st Oct 28 '15 at 07:57

1 Answers1

0

Thank to Jonathan for his idea to use std::bind. So, the solution of this problem:

_fnode = new tbb::flow::function_node<int, double>(*_graph,1,std::bind(&MyClass::fbody, this, std::placeholders::_1));
Jimmy_st
  • 61
  • 1
  • 10