G53OPS - Operating Systems

This course is run at the The University of Nottingham within the School of Computer Science & IT. The course is run by Graham Kendall (EMAIL : gxk@cs.nott.ac.uk)


Threads

This section is based on (Tanenbaum, 1992), pages 507 - 509 (for the interested student this section, pages 509 - 523, contains more details about threads which we do not cover here).

In this section we have so far only considered processes. In this section we take a brief look at threads, which are sometimes called lightweight processes.

One definition of a process is that it has an address space and a single thread of execution. Sometimes it would be beneficial if two (or more) processes could share the same address space and run parts of the process in parallel. This is what threads do.

Firstly, let us consider why we might need to use threads. Assume we have a server application running. Its purpose is to accept messages and then act upon those messages.

Consider the situation where the server receives a message and, in processing that message, it has to issue an I/O request. Whilst waiting for the I/O request to be satisfied it goes to a blocked state. If new messages are received, whilst the process is blocked, they cannot be processed until the process has finished processing the last request.

One way we could achieve our objective is to have two processes running. One process deals with incoming messages and another process deals with the requests that are raised. However, this approach gives us two problems

1. We still have the problem, in that either of the processes could still become blocked (although there are way around this by issuing child processes)
2. The two processes will have to up date shared variables. This is far easier if they share the same address space.

The answer to these type of problems is to use threads.

Threads are like mini-processes that operate within a single process. Each thread has its own program counter and stack so that it knows where it is. Apart from this they can be considered the same as processes, with the exception that they share the same address space. This means that all threads from the same process have access to the same global variables and the same files.

These tables show you the various items that a process has, compared to the items that each thread has.

If you have a multi-processor machine, then different threads from the same process can run in parallel.

Last Page Back to Main Index Next Page

 

 


 Last Updated : 23/01/2002