Code to wait for all CPUs
Posted: Mon Sep 29, 2014 3:39 am
Hi all, I need code to sync all my cores.
This was great fun, I had a couple of attempts before I found a solution.
I was wondering if anyone else has another solution?
These are in the CPU class
This was great fun, I had a couple of attempts before I found a solution.
I was wondering if anyone else has another solution?
Code: Select all
FIL void tCPUs::WaitForAllCPUs()
{
bool AllHere;
ThisCPU()->WaitFlag1 = 1;
AllHere = false;
while (!AllHere)
{
AllHere = true;
for (DWORD i = 0; i < NumberOfCPUs; i++) if (CPU[i]->WaitFlag1 != 1) AllHere = false;
}
ThisCPU()->WaitFlag2 = 1;
AllHere = false;
while (!AllHere)
{
AllHere = true;
for (DWORD i = 0; i < NumberOfCPUs; i++) if (CPU[i]->WaitFlag2 != 1) AllHere = false;
}
ThisCPU()->WaitFlag1 = 0;
AllHere = false;
while (!AllHere)
{
AllHere = true;
for (DWORD i = 0; i < NumberOfCPUs; i++) if (CPU[i]->WaitFlag1 != 0) AllHere = false;
}
ThisCPU()->WaitFlag2 = 0;
AllHere = false;
while (!AllHere)
{
AllHere = true;
for (DWORD i = 0; i < NumberOfCPUs; i++) if (CPU[i]->WaitFlag2 != 0) AllHere = false;
}
}
Code: Select all
volatile BYTE WaitFlag1; // Used to sync all CPUs
volatile BYTE WaitFlag2; // Used to sync all CPUs