diff options
Diffstat (limited to 'oop2w5')
-rw-r--r-- | oop2w5/Blackboard.cpp | 15 |
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])()); } |