void foreach_cell_tmpl(MAP& map, FUNC func, unsigned int nbth) { TraversorCell<MAP, ORBIT, OPT> trav(map); Cell<ORBIT> cell = trav.begin(); std::mutex mutex_map; // launch threads std::thread** threads = new std::thread*[nbth]; ThreadFunction<OPT,ORBIT,MAP,FUNC>** tfs = new ThreadFunction<OPT,ORBIT,MAP,FUNC>*[nbth]; for (unsigned int i = 0; i < nbth; ++i) { std::thread::id& threadId = map.addEmptyThreadId(); tfs[i] = new ThreadFunction<OPT,ORBIT,MAP,FUNC>(func, 1+i,threadId,mutex_map,trav,cell); threads[i] = new std::thread( std::ref( *(tfs[i]) ) ); } // wait for all theads to be finished for (unsigned int i = 0; i < nbth; ++i) { threads[i]->join(); delete threads[i]; map.removeThreadId(tfs[i]->getThreadId()); delete tfs[i]; } delete[] tfs; delete[] threads; }