У меня есть пул потоков: < /p>
Код: Выделить всё
class ThreadPool {
public:
explicit ThreadPool(int threadNumber);
~ThreadPool();
template
auto enqueue(F&& f, Args&&... args)
-> std::future;
private:
std::vector workers;
std::queue tasks;
std::mutex queueMutex;
std::condition_variable condition;
bool stop = false;
};
< /code>
Пул инициализируется с помощью std :: think :: ardware_concurrency () - 1 < /code> Количество потоков (так что есть один бесплатный поток для графического интерфейса).
В моей функции я делаю это: < /p>
std::atomic framesAnalyzed = 0;
for (int i = 0; i < totalFrames; ++i) {
int index = i;
cv::Mat frame = getMatAtFrame(source.files, index);
if (frame.empty()) {
continue;
}
pool.enqueue([&]() {
double quality = Frame::estimateQuality(frame);
source.sorted[index].second = quality;
int done = ++framesAnalyzed;
emit sortingProgressUpdated(done);
});
}
Код: Выделить всё
connect(this, &StackPage::sortingProgressUpdated, this, [this](int current) {
ui->analyzingProgressEdit->setText(QString::number(current) + "/" + QString::number(totalFrames));
});
Что я делаю неправильно?
Подробнее здесь: https://stackoverflow.com/questions/795 ... eads-in-qt
Мобильная версия