sample-2 - SEC. 2.1 81 2.2 THREADS In traditional operating...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
81 2.2 THREADS In traditional operating systems, each process has an address space and a sin- gle thread of control. In fact, that is almost the definition of a process. Neverthe- less, there are frequently situations in which it is desirable to have multiple threads of control in the same address space running in quasi-parallel, as though they were separate processes (except for the shared address space). In the follow- ing sections we will discuss these situations and their implications. 2.2.1 The Thread Model The process model as we have discussed it thus far is based on two indepen- dent concepts: resource grouping and execution. Sometimes it is useful to separate them; this is where threads come in. One way of looking at a process is that it is way to group related resources together. A process has an address space containing program text and data, as well as other resources. These resource may include open files, child processes, pending alarms, signal handlers, accounting information, and more. By putting them together in the form of a process, they can be managed more easily. The other concept a process has is a thread of execution, usually shortened to just thread . The thread has a program counter that keeps track of which instruc- tion to execute next. It has registers, which hold its current working variables. It has a stack, which contains the execution history, with one frame for each pro- cedure called but not yet returned from. Although a thread must execute in some process, the thread and its process are different concepts and can be treated separately. Processes are used to group resources together; threads are the entities scheduled for execution on the CPU. What threads add to the process model is to allow multiple executions to take place in the same process environment, to a large degree independent of one another. Having multiple threads running in parallel in one process is analogous to having multiple processes running in parallel in one computer. In the former case, the threads share an address space, open files, and other resources. In the latter case, processes share physical memory, disks, printers, and other resources. Because threads have some of the properties of processes, they are sometimes called lightweight processes . The term multithreading is also used to describe the situation of allowing multiple threads in the same process. In Fig. 2-1(a) we see three traditional processes. Each process has its own address space and a single thread of control. In contrast, in Fig. 2-1(b) we see a single process with three threads of control. Although in both cases we have three threads, in Fig. 2-1(a) each of them operates in a different address space, whereas in Fig. 2-1(b) all three of them share the same address space. When a multithreaded process is run on a single-CPU system, the threads take
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/20/2011 for the course COP 4600 taught by Professor Yavuz-kahveci during the Spring '07 term at University of Florida.

Page1 / 20

sample-2 - SEC. 2.1 81 2.2 THREADS In traditional operating...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online