Below is some simple code; please note that there is a printf
statement before there is a call to waitFor()
. Why does the program halt for three seconds and then print the message?
int main(int argc, char* argv)
{
producer();
return 0;
}
void waitFor(unsigned int secs) {
unsigned int retTime = time(0) + secs; // Get finishing time.
while (time(0) < retTime); // Loop until it arrives.
}
static void *producer()
{
int s = 3;
printf("Busy for %d seconds", s);
waitFor(s);
return NULL;
}