Here is a method I have used before in the past. Some people might say that CLOCKS_PER_SEC is not accurate, but unless you are timing something down the nanosecond, I don't think this will affect your results greatly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
double checkTime = 0;
clock_t NewTime = clock();
clock_t PrevTime = NewTime;
while (1)
{
NewTime = clock();
checkTime += (double)(NewTime - PrevTime);
PrevTime = NewTime;
if (checkTime > (double)(CLOCKS_PER_SEC))//Multiply CLOCK_PER_SEC by how often you want race to update
{
//Code you want to run in here
checkTime -= (double)(CLOCKS_PER_SEC);
}
}
multi threading in the most basic terms is like having more than one main function running at once - parallel programming. Trust me, you don't wanna go there because the problem you are trying to solve is not that complicated as to start threading it.
mul·ti·thread·ing
/ˈməltiˈTHrediNG/
Noun
A technique by which a single set of code can be used by several processors at different stages of execution.