Modern CPUs have many cores, but games are notoriously difficult to parallelize because of tight data dependencies. Modern engines have moved away from “system-per-thread” (e.g., Audio Thread, Physics Thread) toward Task-Based Job Systems.
Instead of long-lived threads, you break work into thousands of small “Jobs.”
CPU Cores - 1) that sleep when idle.Parallel programming is about managing state.
std::atomic for simple counters or flags. They are much faster than mutexes because they don’t put the thread to sleep.This is a silent performance killer.
alignas(64)).void ProcessParticles(std::vector<Particle>& particles) {
// Split 10,000 particles across 8 cores
const int numTasks = 8;
const int chunkSize = particles.size() / numTasks;
for (int i = 0; i < numTasks; ++i) {
JobSystem::Execute([=, &particles]() {
int start = i * chunkSize;
int end = (i == numTasks - 1) ? particles.size() : (i + 1) * chunkSize;
for (int j = start; j < end; ++j) {
UpdateParticle(particles[j]);
}
});
}
JobSystem::WaitForAll(); // Barrier synchronization
}