Yes, your code for changing worker threads number is ok. There is no analog of omp_get_num_threads() in TBB, so you can't know what exactly number of threads actively work at the moment. In OpenMP number of threadsavailablefor parallel region is determined before entering to the region and is not changed during processing of the region. So calling omp_get_num_threads() inside the region can easily provide you this previosly defined value.
In TBB work load is balanced dynamically between worker threads every time.Number of worker threads processing a parallel construction always changesdepending on workload. Threads stealtasks from each otherdynamically.So there is no reason to request scheduler about currently active threads - this value can be changed next moment.
Regards,
Kirill