C++ (Qt) const int nVolumes = volumeShells.size(); const int nThreads = QThread::idealThreadCount() - 1; QThread** threads = new QThread* [nThreads]; NormalSolver** solvers = new NormalSolver* [nThreads + 1]; for (int i = 0; i < nThreads; ++i) { (solvers[i] = new NormalSolver)->moveToThread(threads[i] = new QThread(this)); qDebug() << connect(threads[i], SIGNAL(started()), solvers[i], SLOT(run())); } solvers[nThreads] = new NormalSolver; volumeShellNormals.resize(nVolumes); for (int i = 0; i < nVolumes; ++i) // для каждого объёма { int nVertices = volumeShells.at(i).size(); int nTriangles = nVertices / 3; int trianglesPerThread = nTriangles / (nThreads + 1); volumeShellNormals[i].resize(nVertices); const float* data = volumeShells.at(i).constData(); float* dest = volumeShellNormals[i].data(); for (int j = 0; j < nThreads; ++j) { const float* begin = data + j * trianglesPerThread, * end = begin + trianglesPerThread; solvers[i]->setSrc(begin, end); solvers[i]->setDst(dest + j * trianglesPerThread); threads[i]->start(); } solvers[nThreads]->setSrc(data + nThreads * trianglesPerThread, data + nVertices); solvers[nThreads]->setDst(dest + nThreads * trianglesPerThread); solvers[nThreads]->run(); for (int j = 0; j < nThreads; ++j) threads[j]->wait(); } for (int i = 0; i < nThreads; ++i) { delete solvers[i]; delete threads[i]; } delete solvers[nThreads]; delete[] solvers; delete[] threads;