Information Technology Reference
In-Depth Information
They make better use of the processor, where different threads can be run when one or
more threads are waiting for data. For example, a thread could be waiting for keyboard
input, while another thread could be reading data from the disk.
They are easier to test, as each thread can be tested independently of other threads.
They can use standard threads, which are optimised for given hardware.
They also have disadvantages, including:
The program has to be planned properly so that threads know on which threads they de-
pend.
A thread may wait indefinitely for another thread which has crashed or terminated.
The main difference between multiple processes and multiple threads is that each process has
independent variables and data, while multiple threads share data from the main program.
H.8.1 Scheduling
Scheduling involves determining which thread should be run on the process at a given time.
This element is named a time slice, and its actual value depends on the system configuration.
Each thread currently running has a base priority. The programmer who created the pro-
gram sets this base priority level of the thread. This value defines how the thread is executed
in relation to other system threads. The thread with the highest priority gets use of the proc-
essor.
NT and 95/98 have 32 priority levels. The lowest priority is 0 and the highest is 31. A
scheduler can change a threads base priority by increasing or decreasing it by two levels.
This changes the threads priority.
The scheduler is made up from two main parts:
Primary scheduler . This scheduler determines the priority numbers of the threads
which are currently running. It then compares their priority and assigns resources to
them depending on their priority. Threads with the highest priority are executed for the
current time slice. When two or more threads have the same priority then the threads are
put on a stack. One thread is run and then put to the bottom of the stack, then the next is
run and it is put to the bottom, and so on. This continues until all threads with the same
priority have been run for a given time slice.
Secondary scheduler . The primary scheduler runs threads with the highest priority,
whereas the secondary scheduler is responsible for increasing the priority of non-
executing threads (which are all other threads apart from the currently executed thread).
It is thus important for giving low priority threads a chance to run on the operating sys-
tem. Threads which are given a higher or lower priority are:
A thread which is waiting for user input has its priority increased.
A thread that has completed a voluntary wait also has its priority increased.
Threads with a computation-bound thread get their priorities reduced. This prevents
the blocking of I/O operations.
Apart from these, all threads get a periodic increase. This prevents lower-priority threads
hogging shared resources that are required by higher-priority threads.
Search WWH ::




Custom Search