Page 321 - DCAP403_Operating System
P. 321

Operating System




                    Notes          When a user is running an interactive program, the system needs to provide especially good
                                   performance for that process. For this reason, Windows 2000 has a special scheduling rule for
                                   processes in the NORMAL PRIORITY CLASS.
                                   Windows 2000 distinguishes between the foreground process that is currently selected on the
                                   screen, and the background processes that are not currently selected. When a process moves
                                   into the foreground, Windows 2000 increases the scheduling quantum by some factor-typically
                                   by 3. (This factor can be changed via the performance option in the system section of the control
                                   panel).
                                   This increase gives the foreground process three times longer to run before a time sharing
                                   preemption occurs.
                                   A thread can be created in a suspended state: The thread will not execute until another thread
                                   makes it eligible via the ResumeThread function. The SuspendThread function does the opposite.
                                   These functions set a counter, so if a thread is suspended twice, it must be resumed twice before
                                   it can run.

                                   To synchronize the concurrent access to shared objects by threads, the kernel provides
                                   synchronization objects, such as semaphores and mutexes.
                                   In addition, synchronization of threads can be achieved by using the WaitForSingleObject or
                                   WaitForMultipleObjects functions. Another method of synchronization in the Win32 API is the
                                   critical section. A critical section is a synchronized region of code that can be executed by only
                                   one thread at a time. A thread establishes a critical section by calling InitializeCriticalSection.
                                   The application must call EnterCriticalSection before entering the critical section, and
                                   LeaveCriticalSection after exiting the critical section. These two routines guarantee that, if
                                   multiple threads attempt to enter the critical section concurrently, only one thread at a time will
                                   be permitted to proceed, and the others will wait in the EnterCriticalSection routine. The critical-
                                   section mechanism is slightly faster than the kernel-synchronization objects.

                                   A fiber is user-mode code that gets scheduled according to a user-defined scheduling algorithm.


                                   A process may have multiple fibers in it, just as it can have multiple threads. A major difference


                                   between threads and  fibers is that threads can execute concurrently, but only one  fiber at a
                                   time is permitted to execute, even on multiprocessor hardware. This mechanism is included in
                                   Windows 2000 to facilitate the porting of those legacy UNIX applications that were written for a
                                   fi ber-execution model.
                                   The system creates a fi ber by calling either ConvertThreadToFiber or CreateFiber. The primary
                                   difference between these functions is that CreateFiber does not begin executing the fi ber that
                                   was created. To begin execution, the application must call SwitchToFiber. The application can

                                   terminate a fiber by calling DeleteFiber.
                                   14.6.2 Inter-process Communication

                                   One way that Win32 applications can do inter-process communication is by sharing kernel objects.
                                   Another way is by passing messages, an approach that is particularly popular for Windows GUI
                                   applications.
                                   One thread can send a message to another thread or to a window by calling PostMessage,
                                   PostThreadMessage, SendMessage, SendThreadMessage, or SendMessageCallback. The
                                   difference between posting a message and sending a message is that the post routines are
                                   asynchronous: They return immediately, and the calling thread does not know when the message
                                   is actually delivered.
                                   The send routines are synchronous-they block the caller until the message has been delivered
                                   and processed.




          314                              LOVELY PROFESSIONAL UNIVERSITY
   316   317   318   319   320   321   322   323   324   325   326