Fix worker index capture in results splitting

This commit is contained in:
Marek Lemańczyk committed 2025-09-20 00:03:53 +02:00
1 parent 22be048c15
commit 83d405c8d5
1 file changed
+25 -24
+25 -24
View File
@@ -625,11 +625,11 @@ internal static class Program
int start = 0;
int baseChunk = count / workerCount;
int remainder = count % workerCount;
for (int worker = 0; worker < workerCount; worker++)
{
int length = baseChunk + (worker < remainder ? 1 : 0);
int chunkStart = start;
start += length;
for (int worker = 0; worker < workerCount; worker++)
{
int length = baseChunk + (worker < remainder ? 1 : 0);
int chunkStart = start;
start += length;
if (length == 0)
{
@@ -639,27 +639,28 @@ internal static class Program
continue;
}
tasks[worker] = Task.Run(() =>
{
List<CandidateResult> localPassed = new(length);
List<CandidateResult> localRejected = new(length);
int end = chunkStart + length;
for (int i = chunkStart; i < end; i++)
{
CandidateResult candidate = sortedResults[i];
if (candidate.PassedAllTests)
{
localPassed.Add(candidate);
continue;
}
int workerIndex = worker;
tasks[workerIndex] = Task.Run(() =>
{
List<CandidateResult> localPassed = new(length);
List<CandidateResult> localRejected = new(length);
int end = chunkStart + length;
for (int i = chunkStart; i < end; i++)
{
CandidateResult candidate = sortedResults[i];
if (candidate.PassedAllTests)
{
localPassed.Add(candidate);
continue;
}
localRejected.Add(candidate);
}
localRejected.Add(candidate);
}
passedSegments[worker] = localPassed;
rejectedSegments[worker] = localRejected;
});
}
passedSegments[workerIndex] = localPassed;
rejectedSegments[workerIndex] = localRejected;
});
}
Task.WaitAll(tasks);