Resources

Microsoft Windows - Events and multi-tasking

Aims

To enable students to:

  1. describe event-driven programming

  2. understand pre-emptive multitasking

  3. describe processes and threads

  4. understand scheduling

Describe event-driven programming

Traditionally programs have been written with the expectation that operations will be carried out in a controlled order. For example a program may enter a loop, executing different functions based on what keys an operator has pressed. The programmer has full control over this process, including deciding when the loop should be entered and left.

Windows programming is event-driven and graphic object oriented - these terms should be familiar from elsewhere in the C++ course covered to date. Programming in Windows creating objects and modifying their properties based on different events. The developer has no control over which events are generated by the Windows operating system, instead they must develop applications that respond to them.

Windows programs provide users with a standardised environment of menus, buttons, list boxes, etc. Such facilities are provided by the operating system for use by applications, ensuring a common look and feel. This cuts down on the amount of work required by the application developer, the operating system provides the majority of the user interface leaving more time to consider the real problem being addressed by the program.

Understand pre-emptive multitasking

Operating systems such as Windows 95, 98 and NT are capable of running many different programs simultaneously through multitasking. This is a technique whereby each application is given a very short period in which it can use the processor, before another program is allotted time. In previous versions of Windows applications had to be written in a considerate fashion, relinquishing use of the processor periodically to allow others to continue their work. Later versions of Windows introduced pre-emptive multitasking where the operating system will give every application on the system a fair share of the processor, those that are developed in a non-considerate fashion will no longer be able to monopolise system resources.

Besides ensuring responsive systems for end users, pre-emptive multitasking is also easier to develop applications for than the method employed by earlier versions of Windows. Developers no longer need to consider other applications that may be executing on the same machine, to all intents and purposes theirs is the only program being executed - the operating system will ensure fairness across the system.

Describe processes and threads

A process is a program that is loaded into memory and prepared for execution. Each has its own private address space separate from all others on the system. Data within each process space is totally protected form others, it is not possible for others to gain access. In this way processes are very similar to objects and their protected data members.

Each process has at least one thread of execution, each one representing a path of execution through the program.

As discussed previously the operating system is responsible for ensuring each program is allotted a certain amount of processor time. This allocation is based on a thread basis, each thread in operation on the system being given the same amount of time with the processor.

Understand scheduling

If every thread on the system was given equal amounts of processor time users would be presented with a very sluggish interface. Consequently, each thread is allocated a priority which dictates which one will have access to the processor next. The priority is based on:

  1. the priority of the process

  2. the priority of the thread within the process

  3. dynamic priority boost applied by the system

The first two factors in determining the thread priority are controlled by the owning process. The final factor is controlled by the operating system based on how long the thread has been waiting to execute, whether the parent process has input focus, etc.

Downloads