aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-14 18:44:57 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-14 18:44:57 +0100
commit76a4bcf9845f14ad0d679696f47f58dd8ca0a0b4 (patch)
tree313e7cacde356e47d757744d0964cef2a24e8bca
parent114fb12ed445b0d7472655fc26da052a2a2aa167 (diff)
parentf083fcc2be0e0d3b6e356f0a814f407a273e345a (diff)
Merge branch 'master' of pipeframe.xyz:school/oop-huiswerk
-rw-r--r--oop2w5/Blackboard.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/oop2w5/Blackboard.cpp b/oop2w5/Blackboard.cpp
index 9c98992..26ced40 100644
--- a/oop2w5/Blackboard.cpp
+++ b/oop2w5/Blackboard.cpp
@@ -35,14 +35,15 @@ void Blackboard::spawn_subthreads(unsigned start_index, unsigned length) {
// beslis beste strategie (lelijk linear zoeken want maar 3 elementen)
- lock_guard<mutex>* bbs_lock = new lock_guard<mutex>(_bbs_lock); // lock guard
- _bbs->setBestStrategy(_fitness[start_index]); // beste fitness altijd in _fitness
- for (unsigned i = start_index; i < end_index; i++)
- _bbs->setBestStrategy(max(_fitness[i], _bbs->getBestStrategy()));
unsigned best_index = start_index;
- for (unsigned i = start_index; i < end_index; i++)
- if (_fitness[i] == _bbs->getBestStrategy()) { best_index = i; break; }
- delete bbs_lock; // handmatig mutex vrijgeven (want volgende regel code duurt lang)
+ {
+ lock_guard<mutex> bbs_lock (_bbs_lock); // lock guard
+ _bbs->setBestStrategy(_fitness[start_index]); // beste fitness altijd in _fitness
+ for (unsigned i = start_index; i < end_index; i++)
+ _bbs->setBestStrategy(max(_fitness[i], _bbs->getBestStrategy()));
+ for (unsigned i = start_index; i < end_index; i++)
+ if (_fitness[i] == _bbs->getBestStrategy()) { best_index = i; break; }
+ }
_results.push_back((_bbs->*resultStrategies[best_index])());
}