How does a program know actually what a second is?

839 views

So if a program needs to wait 10 seconds for something, how it is actually calculating it if the processors speed continously changes? (And i’m talking about offline programs that does not use NTP)

In: 361

20 Answers

Anonymous 0 Comments

For the five year old:

Computers have a clock inside them.

For the 10 year old:

Computers have a clock inside them and there is a special function that programs can call to get the current time.

For the 14 year old:

When programming your application you can call a function to get the the current or elapsed time. You can also program it so it asks the computer to “call it back” when a certain amount of time has elapsed.

The computer keeps track of the current time in 2 ways. First there is a special chip that keeps track of the time, and it has a small battery which keeps power to it. The computer references this when it’s turned on. This is why it knows the current time even when power is removed. Second, when connected to a network or internet, it sends a request for the current time, and the closest time server responds with the current time.

For the 16 year old:

(Above +) Computers also have a special circuit called a “clock” which operates at a know frequency. The clock “ticks” at the speed in which a computer can process instructions at the lowest level (CPU instructions, not application code). Because the frequency is known, the number of ticks per second is also known. Most CPUs and microprocessors use a quarts crystal, which vibrates at a known frequency, to generate these ticks.

You are viewing 1 out of 20 answers, click here to view all answers.