How does multi- processing and threading works in win

Started by
3 comments, last by Fidelio66 19 years, 2 months ago
I am trying to understand how windows does it multitasking stuff, and how my programming fits into this... - A process have 3 states, running, ready and blocked(waiting for something IO or whatever). - A process that want to use a shared resource, must enter critical mode... (so it get exclusive access to the resource). How does this happens? - The scheduler in windows is the part that make sure each thread get cpu time. It select which process that gets cpu time based om priority. - The priority is set based on what type of process it is etc etc. - Priority is altered by the scheduler, if a process uses all of it cpu-time it will get higher priority. If it is not using time, it will get lower priority. The Scheduler will boost the priority for each process now and then, so they get cpu-time. I read that windows does not have a centralized scheduler. When the process is done with its cpu-time, it will launch the scheduler and find out who's next process to get cpu time... ??? When 2 processes wants a resource, they will ask to get into critical mode, and they check if they can do so by checking a mutex (a bool). But how does windows recover if one process hangs? What if it hangs in critical mode? If the scheduler is run at the end of the cpu-time a process has, how does the process knows when to stop and launch the scheduler (so other processes gets cpu-time)? The little win32 programming I have done, I have never asked for "critical mode", or never told the "scheduler" that I'm done for now ... I must guess that many of the win32 functions takes care of this for me (GetMessage(), Sleep() etc etc). Could someone elaborate on scheduler/multi-processing/multi-threading for me? I just started to read "Modern Opertaing Systems - Tanenbaum" ... but it is not very clear on how windows does it stuff
Advertisement
Quote:I read that windows does not have a centralized scheduler. When the process is done with its cpu-time, it will launch the scheduler and find out who's next process to get cpu time... ???


If I understand what you're alluding to, that's not true anymore. Win32 has pre-emptive multitasking. The OS itself will interrupt the running process. It doesn't have to wait for it to relinquish control.

Quote:But how does windows recover if one process hangs? What if it hangs in critical mode?


It's a serious problem. You can still get the system to hang, though it has gotten much better.

Quote:Could someone elaborate on scheduler/multi-processing/multi-threading for me? I just started to read "Modern Opertaing Systems - Tanenbaum" ... but it is not very clear on how windows does it stuff


You should really ask your OS instructor. They are there to answer your questions, you know. [grin]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
on linux yes ... windows??? no

that is way I hope for someone to better explain stuff to me her

The book talks about windows 2000, but I also belive the explanation is kinda "true" in its context, but not true you know ...

I also belive the windows will interupt, because I could make an while(true) loop in a silly win32 program ... and the only thing that would happen is that my program draws 99% cpu, but the software is still "close-able".
It's threads that have running states, grab resources, etc. Not processes. Processes are just buckets of threads and a few other attributes.

Processes have a base priority. When a thread is created it gets this priority by default.

The scheduler has a queue for each priority level. All threads that aren't blocked are in thier approriate queue.

When the scheduler starts a new thread it also makes a note of how long it will be able to run. This number is called the quantum.

The kernel sets up a timer interrupt. This interrupt goes off every millisecond or so (it varies from OS to OS and is sometimes adjustable per-machine to some extent). Part of the work of the interrupt handler is to check to see if the current thread has used up it's time. If it has the scheduler is notified.

The scheduler bumps the current thread to the back of the queue for it's priority. It then takes the highest-priority runnable thread and fixes up the cpu to run that one instead of the old one.

Repeat forever.

If your program doesn't give up the cpu voluntarily (by doing IO typically) the OS will take control away, that's why your test app was still closeable. Linux and (modern) Windows are more or less the same at this level. What your OS teacher says about scheduling applies to either. The details are different of course but the basic concepts are the same.
-Mike
Quote:Original post by DarkSlayer
on linux yes ... windows??? no


If you read books and they mention windows, they might mean Windows 3.1 if the book is old. Windows 3.1 had cooperative multitasking if I remember correctly.
The Windows NT/2000/XP process structure and scheduler is just as robust and professional as UNIX (Linux), fully preemptive with priority levels.

This topic is closed to new replies.

Advertisement