Jump to content
  • Advertisement
Sign in to follow this  
brwarner

General Computing Curiosity Questions

This topic is 3625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, over my time working with programming and such I have come across a few general things about computers/programming that have puzzled me and I never really found out what the answers were. I don't need the answers for any specific programming problem or issue, I'm just curios. 1) Windows runs multiple programs "supposedly" simultaneously but really just diverts the processor over to a new task (to my knowledge). How is consistency maintained? For instance, programs use registers and the stack for data storage, won't these be altered when another program is switched to processor priority? How are they recovered, and how does Windows know when to switch such that these problems are avoided? 2) The processor is a single task machine, basically it points to a specific location in RAM and runs the instruction there, then moves to the next and so on - unable to run any sort of background task. So when Windows runs a program, it is loaded into RAM, yet Windows is still able to run other tasks. How is this accomplished, does it insert instructions into the code as it loads into RAM at points to call a windows function or something? Agg, I had a few others in my mind as time went on but now I forget them... Oh well, I shall post if I remember any. Also, correct any information I may have assumed that is incorrect, which may be the cause why I don't know the answer in the first place...

Share this post


Link to post
Share on other sites
Advertisement
I don't know about 2), but I can say something about 1). When the OS switches the processor to a new task, this is called a "context switch". During a context switch, the entire state of the processor is saved, and a new state is loaded. This includes stuff like register state. You can look up "context switch" on wikipedia for more information.

Share this post


Link to post
Share on other sites
A text-book on Operating Systems can answer all of these questions in great detail if you're really curious ;)

1) As stated above, the OS backs up the full CPU state whenever it has to mess with a running program.

2) Firstly, RAM is virtualilzed these days. When you think you're holding a pointer to a specific byte of RAM, the OS is actually performing offsets and checking permissions and stuff for you behind the scenes. It's even possible that a bit of memory that you have a pointer to isn't even located in RAM, in which case the CPU will trigger a page fault, which probably fires off some kind of interrupt signal, which switches control back to the OS, which then loads the required data from disc into RAM and then switches back to your program.
The answer to your question is probably "interrupts" and "interrupt handlers"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!