Question:
Mind blowing question?
anonymous
1970-01-01 00:00:00 UTC
Mind blowing question?
Nine answers:
Dimitar
2013-12-15 19:48:06 UTC
First,



Every computer has an internal clock.

It's a little circuit that you save Date and Time to, and it keeps ticking, counting the time.

It saves that time as a 32/64 bit integer, which keeps

Year, Month, Day, Hour, Minute, Second, Milisecond data.



It's why the 16 bit systems had a error some time ago, the 16 bits weren't enough for all that.



Most novice programmers don't know how this mechanic work, so hey do some hacky for loops (BAD IDEA, Eats computer resources BAD).



Instead, you should use any integrated wait commands, timers, clocks.



A program usually timestamps the time a timeout was executed.

Then it checks (efficiently so) if the current timestamp (current OS time) is late enough (5 seconds later than the marked timestamp), then it runs some code.



Putting it basic, the only way a computer can tell time is by checking the internal clock once in a while, and checking if it has anything to do on a particular time

(time scheduling).



If you need to mess with this, and not use default timeouts and other similar things the environment you work in, you will have a lot of learning to do, as this is a somewhat serious engineering problem. (Which is why timing is frowned upon in computers).
Nikhil
2013-12-15 19:42:12 UTC
Hey its easy!!!

Just like a clock..It saves the time first and then keep moving like any other device..

The second question is like this that the computer uses a relative method for waiting till such and such time..

If you installed a program and after finishing it it is asking for your permission to reboot or etc then what your PC do is that it saves the time when you fiinished a task and calculates till how much time it has to wait to shut down automatically..When the time reaches it does what it was told to like an alarm..
Zeke
2013-12-15 19:40:16 UTC
mind=blown
green meklar
2013-12-18 20:13:52 UTC
It has a clock inside it.



Actually, more than one clock. There's a relatively slow CMOS clock that tells the computer what time it is when it starts up, and then the processor also has its own extremely fast clock that sends pulses to activate the processor circuits. Other components, such as the GPU or the network card, probably have their own clocks as well, similar to the one in the processor.
Jim
2013-12-16 02:37:54 UTC
there is a 14.31818MHz (I guess you could call it a silver can) clock oscillator tied to the RTC (Real Time Clock) chip. the RTC also contains a very small static CMOS RAM which contains your SETUP information about your hardware. the RTC is connected to the CR2032 battery on your motherboard. if the battery dies (4 years), guess what? you lose all that info. so go into CMOS SETUP (BIOS) and write it all down or memorize it if you have a photographic memory.



the RTC is separate from the former 8254 Timer chip which is now part of the bridge chips, which handles low frequency pulses including PWM I think, down to about 2Hz-32KHz.



the RTC I don't think is consulted very often, maybe only once every boot-up at the time one of the Timers is set to a specific but very low frequency, 18.2Hz I think. that Timer is not too accurate, but it's good for the day, just not for a week. plus, the counter portion of the Timer resets, so when you get the current count value, it's only good for so long these are typically tied to a hardware interrupt line, and this is has some very short and fast code associated with that particular interrupt number assigned at a specific address that calls a function in the OS to let it know the timer ticked. if it can't service the interrupt in time, that will probably be handled by ignoring by masking the interrupt or something similar. usually whatever surrounds that will be fast assembly code.

the Interrupt lines are handled (it used to be) through an interrupt chip on the original IBM PC. now this is handled through one of the bridge chips I think, which has consolidated a lot of those separate chips into just 2 big chips, one for buses and one for other functionality (but I don't know that exactly because it's been a while since I looked, I may have that close to right).



only recently do we have high precision timers, and I *think* this is due to a new feature in modern CPU's, thought I skimmed past it when browsing through the i7 manual. to look up info about the RTC, get info on your particular chipset your motherboard has, such as Intel X79. port numbers should be the same since the original PC, but some have changed to to things like LPT1-LPT2: and COM1-COM4: falling out of disuse and other things.
anonymous
2013-12-15 23:12:09 UTC
A computer keeps track of time by saving how many seconds passed since the creation of UNIX.

Due to possible overflow, year2k made some computers to think they went back in time.

Do you know how do quartz clocks work? They're electronics but they do count seconds very precisely.

Computers also know how much time it takes for a processing cycle to complete. By measuring processing cycles (easy) and multiplying that by how much time it takes for a cycle to complete, you can calculate how much time passed.

In C, all the programmer needs to do to work with time is to call the time() function.

It's located in the standard library, so it's up to the implementer to figure out how to make the computer give the programmer the correct time.

Doesn't the OS handle that in some cases?
Zachary
2013-12-15 20:39:35 UTC
well, the way I've understood it is that you calculate the time it takes for one message to be sent and get a blank response. With that time calculated, you can then say that one tick(message sent and returned) takes 20 milliseconds, then every tick, add 5 milliseconds to it. then you can use modulus coding to tell if 1000 milliseconds have gone by, and if so, 1 second has gone by. this constant has been embedded into the operating system and cannot be changed, but only read.
Jousha
2013-12-15 19:50:41 UTC
Well for the record a computer only computes what we tell it do and it can't tell time because there a little program on your computer that keeps track of time and when you setup your computer you have to tell it what time it is i order for the program on your computer to keep track of time!



Also a programmer dosnt tell a computer to wait just to process somthing! its because it takes time to process that thing plus if you want to know why it takes a long time to do somthing its because it has to go through tons and and tons of work which is more work then you will ever have!
?
2013-12-15 19:52:36 UTC
This isn't really mindblowing, at least not for computer engineers.



Computers use a quartz crystal to keep track of time. Basically, when you apply a voltage to a electrode near a properly cut crystal, the crystal starts behaving like an RLC circuit. If you've ever taken a basic electric circuit theory course, you'd know that an RLC circuit will exhibit a certain resonant frequency. This resonant frequency is how time is measured (if you recall from your physics class, frequency is measured in Hertz, or 1/seconds).



The use of the crystal as the time keeper is known as a crystal oscillator, and the oscillator is used in real-time clocks; the same ones as those in quartz clocks and watches.



Nowadays in modern operating systems, the time measured by your computer will also be synchronized with the time reported by an external server at a regular interval (which, most of the time, will use an atomic clock).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...