4 finally the use of threads is also motivated by the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ogram counter, its own register states, and its own stack. But all the threads of a process share the same address space. Hence they also share the same global variables. In addition, all threads of a process also share the same set of operating system resources, such as open files, signals, accounting information, and so on. Due to the sharing of address space, there is no protection between the threads of a process. However, this is not a problem. Protection between processes is needed because different processes may belong to different users. But a process (and nence all its threads) is always owned by a single user. Therefore, protection between multiple threads of a process is not necessary. If protection is required between two threads of a process, it is preferable to put them in different processes, instead of putting them in a single process. Threads share a CPU in the same way as processes do. At a particular instance of time, a thread can be in any one of several states - running, blocked, ready, or terminated. Due to these similarities, threads are often viewed as miniprocesses. In fact, in operating systems with threads facility, a process having a single thread corresponds to a process of a traditional operating system [see Figure 14.7(a)]. Threads are often referred to as lightweight processes and traditional processes are referred to as heavyweight processes. Motivations for Using Threads The main motivations for using a multithreaded process instead of multiple singlethreaded processes for performing some computation activities are as follows: 1. The overheads involved in creating a new process are, in general, considerably greater than those of creating a new thread within a process. This is mainly because when a new process is created, its address space has to be created from scratch, although a part of it might be inherited from the process's parent process. However, when a new thread is created, it uses the address space of its process that need not be created from scratch. 2. Due to the sharing of address space and other...
View Full Document

Ask a homework question - tutors are online