OSch4 - Chapter 4 Threads Threads 1 Overview !...

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

View Full Document Right Arrow Icon
Threads 1 Threads 1 Chapter 4 Threads 2 Overview ! Single-threaded process – multithreaded process: " A thread is a basic unit of CPU utilization. " Traditional process has a single thread of control. " Multithreaded process can perform more than one task at a time. ! Many applications are multithreaded. " A web browser might have one thread displaying images while another thread retrieving data from the network. " A word processor may have a thread for responding to keystrokes from the users, and another thread for performing spelling and grammar checking in the background. Threads
Background image of page 1

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

View Full DocumentRight Arrow Icon
Threads 2 3 Overview (cont’d) ! In many situations, an application may be required to perform several similar tasks. " A web server accepts several client requests for web pages. " If the web server run as a traditional single-threaded process … it would be able to service only one client at a time. ! Solution 1: " When the server receives a request, it creates a separate process to service that request. # E.g., fork() . " This process-creation method was in common use before threads became popular. " Process creation is time consuming and resource intensive . ! Solution 2: " It is more efficient to use one process that contains multiple threads. " When a client request is accepted, the server (a thread) would create another thread to service the request . Threads 4 Overview (cont’d) ! A thread comprises: " A thread ID. " A program counter. " A register set. " A stack. ! It shares with other threads belonging to the same process: " Code section. " Data section. " Other operating-system resources, such as open files. Threads
Background image of page 2
Threads 3 5 Overview (cont’d) Threads 6 Overview (cont’d) ! Benefits: " Responsiveness : # Application can continue running even if part of it is blocked or is performing a lengthy operation. # A multithreaded web browser allow user interaction in one thread while an image was being loaded in another thread. " Resource sharing : # Threads share the memory and the resources of the process to which they belong. " Economy : # Allocating memory and resources for process creation is costly. # In Solaris, creating a process is about thirty times slower than is creating a thread. Context switching is about five times slower. " Utilization of multiprocessor architectures : # Threads may be running in parallel on different processors. # A single-threaded process can only run on one CPU, no matter how many are available. Threads
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 7 Overview (cont’d) ! Many operating system kernels are now multithreaded. " Several threads operate in the kernel. " Each thread performs a specific task. " For example, Linux uses a kernel thread for managing the amount of free memory in the system. Threads
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course CMP 426 taught by Professor Gwangs.jung during the Spring '12 term at CUNY Lehman.

Page1 / 24

OSch4 - Chapter 4 Threads Threads 1 Overview !...

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

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