| | | | program code. Every process must have at least one thread. The purpose of threads, of course, is to allow a process to maintain more than one line of execution, that is, to do more than one thing at a time. In a multiprocessor environment (a computer with more than one CPU), Windows NT (but not Windows 9x) can assign different threads to different processors, providing true multiprocessing. In a single-processor environment, the CPU must provide time slices to each thread that is currently running on the system. We will discuss time slices in detail in Chapter 12, Threads. | | | | | | Figure 9-1 shows an overview of the Windows NT architecture. Let us review some of the items shown in this figure. | | | | | | A Pentium microprocessor has four privilege levels, also known as rings, that control such things as memory access and access to certain sensitive CPU instructions (such as those related to security). Every thread executes at one of these privilege levels. Ring 0 is the most privileged level, with complete access to all memory and CPU instructions. Ring 3 is the least privileged level. | | | | | | In order to maintain compatibility with non-Intel systems, the Windows operating systems support only two levels of privilege Ring 0 and Ring 3. When a thread is running in Ring 0, it is said to be in kernel mode. When a thread is running in Ring 3, it is said to be in user mode. Low-level operating system code executes in kernel mode, whereas, in general, user application code runs in user mode. | | | | | | Note that an application thread will switch from user mode to kernel mode when making certain API function calls that require a higher privilege level, such as those that involve accessing files or performing graphics-related functions. In fact, some user threads can spend more time in kernel mode than in user mode! | | | | | | However, when the kernel mode code is completed, the user thread is automatically switched back to user mode. This prevents the programmer from being able to write instructions that run in kernel mode the programmer can call only system functions that run in kernel mode. | | | | | | If you are running Windows NT, you can see for yourself when a thread is running in user mode and when it is running in kernel mode. To do this, start the Performance Monitor from the Administrative Tools item on the Start Menu. Select Add To Chart from the Edit menu. Then add % User Time and % Privileged Time from the Counters list. Next, do some graphics-intensive things, such as opening | | |