mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Adjust mutex scope in walkMapParallel:
This commit corrects a technical flaw that was introduced with commit
7c12f01358: as written, a mutex that is
intended to help provide synchronization for multiple threads as they
are each walking the map, is declared so that each thread is passed a
dangling reference to a unique mutex.
This commit hoists the mutex outside the thread creation loop, so all
threads use a single mutex and eliminating the dangling reference.
This commit is contained in:
@@ -314,6 +314,10 @@ SHAMap::walkMapParallel(
|
||||
|
||||
std::array<std::stack<StackEntry, std::vector<StackEntry>>, 16> nodeStacks;
|
||||
|
||||
// This mutex is used inside the worker threads to protect `missingNodes`
|
||||
// and `maxMissing` from race conditions
|
||||
std::mutex m;
|
||||
|
||||
for (int rootChildIndex = 0; rootChildIndex < 16; ++rootChildIndex)
|
||||
{
|
||||
auto const& child = topChildren[rootChildIndex];
|
||||
@@ -324,7 +328,6 @@ SHAMap::walkMapParallel(
|
||||
std::static_pointer_cast<SHAMapInnerNode>(child));
|
||||
|
||||
JLOG(journal_.debug()) << "starting worker " << rootChildIndex;
|
||||
std::mutex m;
|
||||
workers.push_back(std::thread(
|
||||
[&m, &missingNodes, &maxMissing, this](
|
||||
std::stack<StackEntry, std::vector<StackEntry>> nodeStack) {
|
||||
|
||||
Reference in New Issue
Block a user