I have noticed that if I put the call to task_scheduler_init between curly braces the call has no effect. To demonstrate here's my code:
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include "tbb/compat/thread"
using namespace System;
//Task class:-
class TaskClass : public tbb::task
{
public:
TaskClass(){};
~TaskClass(){};
tbb::task* execute()
{
std::stringstream ss; // to keep the output in order
ss<<"Thread id: "<
std::cout<
return NULL; } };
int main(array ^args) { { // these make a difference tbb::task_scheduler_init init(6); } TaskClass& task1 = *new(tbb::task::allocate_root()) TaskClass(); tbb::task::enqueue(task1,tbb::priority_normal); TaskClass& task2 = *new(tbb::task::allocate_root()) TaskClass(); tbb::task::enqueue(task2,tbb::priority_normal); TaskClass& task3 = *new(tbb::task::allocate_root()) TaskClass(); tbb::task::enqueue(task3,tbb::priority_normal); TaskClass& task4 = *new(tbb::task::allocate_root()) TaskClass(); tbb::task::enqueue(task4,tbb::priority_normal); TaskClass& task5 = *new(tbb::task::allocate_root()) TaskClass(); tbb::task::enqueue(task5,tbb::priority_normal); TaskClass& task6 = *new(tbb::task::allocate_root()) TaskClass(); tbb::task::enqueue(task6,tbb::priority_normal); std::string temp; std::cin>>temp; // letting other threads execute return 0; } With braces the output: Thread id: 6640 Thread id: 6640 Thread id: 6640 Thread id: 6640 Thread id: 6640 Thread id: 6640 Without braces the output: Thread id: 6884 Thread id: 6200 Thread id: 7020 Thread id: 5984 Thread id: 6420 Thread id: 6884 From documentation I understand that with 3.x each thread from application gets its own pool. But in the above example it is the same thread but seems like with curly braces the pool doesn't get created with the set number. I'm using TBB version 4.0 update 1. Is this the intended behavior or a bug? Thank you.



