From 68f62bebeedfefd07789d2be3a88fc1340f4cab0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Dec 2008 16:44:10 +0100 Subject: [PATCH] Fix race condition while checking if threads are still active. --- SolversThreads/SolversThreads.cpp | 2 +- main.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SolversThreads/SolversThreads.cpp b/SolversThreads/SolversThreads.cpp index 2e3bbc1..71161c7 100644 --- a/SolversThreads/SolversThreads.cpp +++ b/SolversThreads/SolversThreads.cpp @@ -315,7 +315,7 @@ void *ASAthread(void *data) //log in logfile *(PtrTP->Ptr_log) << PtrTP->generations * deme.size() << " " << (PtrTP->Ptr_pop->extractBestIndividual()).getFitness() << endl; //sinal exit - *(PtrTP->isActive) = false; + __sync_sub_and_fetch(PtrTP->isActive,1); PtrTP->exit->notify_one(); } return 0; diff --git a/main.cpp b/main.cpp index 565903b..da6d6b3 100644 --- a/main.cpp +++ b/main.cpp @@ -639,7 +639,8 @@ while (choice != -1) { } //The main cycle has finished: we wait for all threads to finish for (int i=0; i