From 90043eb7d7c95873775ae5b85388a5046e3d5ac0 Mon Sep 17 00:00:00 2001 From: az13js <1654602334@qq.com> Date: Fri, 12 Feb 2021 02:55:01 -1000 Subject: [PATCH] jthread -> thread --- .gitignore | 5 ++++- src/GeneticAlgorithm/Multithreading.cpp | 10 ++++++---- src/main.cpp | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 07bebb9..2a7dfb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ build/* -!build/.gitkeep \ No newline at end of file +!build/.gitkeep +*.sh +*.out + diff --git a/src/GeneticAlgorithm/Multithreading.cpp b/src/GeneticAlgorithm/Multithreading.cpp index 3019de6..403b0d3 100644 --- a/src/GeneticAlgorithm/Multithreading.cpp +++ b/src/GeneticAlgorithm/Multithreading.cpp @@ -37,9 +37,9 @@ namespace GeneticAlgorithm { long double r ) { using namespace std; - jthread** threads = new jthread*[this->threadNumber]; + thread** threads = new thread*[this->threadNumber]; for (unsigned long i = 0; i < this->threadNumber; i++) { - threads[i] = new jthread([]( + threads[i] = new thread([]( MainProcess* process, unsigned long numberOfChromosome, unsigned long lengthOfChromosome, @@ -54,6 +54,7 @@ namespace GeneticAlgorithm { }, this->process[i], numberOfChromosome, lengthOfChromosome, min, max, maxLoop, stopFitness, keep, r); } for (unsigned long i = 0; i < this->threadNumber; i++) { + threads[i]->join(); delete threads[i]; } delete[] threads; @@ -66,9 +67,9 @@ namespace GeneticAlgorithm { long double r // 基因突变的概率 ) { using namespace std; - jthread** threads = new jthread*[this->threadNumber]; + thread** threads = new thread*[this->threadNumber]; for (unsigned long i = 0; i < this->threadNumber; i++) { - threads[i] = new jthread([]( + threads[i] = new thread([]( MainProcess* process, unsigned long maxLoop, long double stopFitness, @@ -79,6 +80,7 @@ namespace GeneticAlgorithm { }, this->process[i], maxLoop, stopFitness, keep, r); } for (unsigned long i = 0; i < this->threadNumber; i++) { + threads[i]->join(); delete threads[i]; } delete[] threads; diff --git a/src/main.cpp b/src/main.cpp index 5dbea18..d96b6ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ * */ #include -#include "GeneticAlgorithm.h" #include "GeneticAlgorithm/MainProcess.h" using namespace GeneticAlgorithm; -- Gitee