|
|
Uses for Multiple Threads Continued from Thread Scheduling Just how are multiple threads used in today's applications? Knowing exactly what an application is doing with its threads is difficult when you don't have access to its source code, but finding out how many threads an application uses is easy enough. One of the components that comes with Windows 95 is the System Monitor, found in the Start | Programs | Accessories | System Tools menu. (If you did not install it the first time around, click Start | Settings | Control Panel and open the Add/Remove Programs icon.) One of the items of information that System Monitor will display for you is the number of threads running in the system, as shown in Figure 2. By starting an application with System Monitor running and watching the thread count, you can determine how many threads the application uses. If the application uses a dedicated thread for background printing, you'll probably see the thread count bump up by 1 when you print a document. You'll discover that Windows 95 uses several threads itself, because even with no applications other than System Monitor running, you'll never see the thread count drop below 12 or 13. Windows 95 uses one thread for nothing but fault handling, which makes it easier for the operating system to recover when an application suffers a general protection fault or causes other severe errors. It also runs animated cursors in a dedicated thread that is assigned a high priority but spends most of its time suspended, waiting for the moment to draw the next "frame." The Windows 95 shell also takes advantage of the operating system's multithreading capabilities. For example, each window that you open in the shell is managed by a separate thread. If you drag-copy a file from one window to another, the thread associated with the window on the receiving end of the exchange performs the copy operation. The Taskbar is assigned its own thread, as is the window that represents the desktop. Shell-extension DLLs are run in separate threads so that if a shell extension goes down, it won't take the shell with it. The shell even uses one thread to gather file-change notifications and lump them together. This way a window doesn't get bombarded with notifications if someone opens a DOS window and copies 100 files to a folder whose contents are visible in an Explorer window. Windows NT finds still other uses for threads. For example, Windows NT uses a priority-0 thread to zero the contents of unused memory pages. It also uses a dedicated raw-input thread to capture mouse and keyboard events, convert them into messages, and distribute the messages to the various message queues. Published as Tutor in the 12/05/95 issue of PC Magazine. |
|
TOP |
Copyright (c) 1997 Ziff-Davis Inc. |