diff --git a/.gitignore b/.gitignore index 07bebb9d96edde9f1c545fb26885357b4a4e3ab8..2a7dfb4f921c7c7b75ee6ca7d4b173b1a7c118ef 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 3019de6d9ad366052f365029f06446f29c521fc1..403b0d390b83087bd119630ab798ff724fdf56ac 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 5dbea1895d3df3f1084e5e9ff0a9248063f7ff98..d96b6ca5c225db54069646321dab7baa1bc67085 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ * */ #include -#include "GeneticAlgorithm.h" #include "GeneticAlgorithm/MainProcess.h" using namespace GeneticAlgorithm;