Am trying to limit the number of threads at anytime to be equal to utmost the number of cores available. Is the following a reasonable method? Is there a better alternative? Thanks!
    boost::thread_group threads;
    iThreads = 0;
    for (int i = 0; i <  Utility::nIterations; i++)
    {
        threads.create_thread(
            boost::bind(&ScenarioInventory::BuildInventoryWorker, this,i));
        thread_limiter.lock();
        iThreads++;
        thread_limiter.unlock();
        while (iThreads > nCores)
            std::this_thread::sleep_for(std::chrono::milliseconds(1)); 
    }
threads.join_all();
void ScenarioInventory::BuildInventoryWorker(int i)
{
    //code code code....
    thread_limiter.lock();
    iThreads--;
    thread_limiter.unlock();
}