/* L-11 MCS 572 Fri 3 Feb 2012 : hello_task_group.cpp
 * The code below is a hello world with threading building blocks.
 * The makefile for Mac OS X contains the following information:
 *
 * TBB_ROOT = /Users/jan/Courses/MCS572/TBB/tbb40_233oss
 *
 * hello_task_group:
 *	g++ -I$(TBB_ROOT)/include -L$(TBB_ROOT)/lib \
 *           hello_task_group.cpp -o /tmp/hello_task_group -ltbb
 *
 * The code is adjusted from an online article of Arpan Sen
 * "Learning the Intel Threading Building Blocks Open Source 2.1 Library"
 * available via http://www.ibm.com/developerworks/aix/library/" */

#include "tbb/tbb.h"
#include <cstdio>
using namespace tbb;

class say_hello
{
   const char* id;
   public: 
      say_hello(const char* s) : id(s) { }
      void operator( ) ( ) const 
      {
         printf("hello from task %s\n",id);
      }
};

int main( )
{ 
   task_group tg;
   tg.run(say_hello("1")); // spawn 1st task and return
   tg.run(say_hello("2")); // spawn 2nd task and return 
   tg.wait( );             // wait for tasks to complete
}

