Unformatted text preview:

Chapter 4.1: ThreadsThreads – Our Chapter 4 OutlineOverview of ThreadsMultiple Threads of ControlSlide 5Single and Multithreaded ProcessesBenefits are ManyUser ThreadsThread Models – Many to One ModelMany-to-One Model – a Visual DepictionThread Models: One-to-One ModelOne-to-One Model – a VisualThread Models: Many-to-Many ModelMany-to-Many ModelThread LibrariesThread Libraries - morePthreadsLinux Threads – taken from Operating Systems Internals and Design Principles, by William StallingsLinux Threads – taken from Operating Systems Internals and Design Principles, by William StallingsSlide 20Example forthcoming:Multithreaded C program using Pthreads APICloser look: header code extracted…Java Threads using the Java APIMultithreaded Java program using Java API (1 of 2)Multithreaded Java program using Java API (2 of 2)Finishing Threads with Java APIJava Thread StatesEnd of Chapter 4.1Chapter 4.1: ThreadsChapter 4.1: Threads4.2Silberschatz, Galvin and Gagne ©2005Operating System ConceptsThreads – Our Chapter 4 OutlineThreads – Our Chapter 4 OutlineThis chapter addresses multi-threaded computing systemsMost modern operating systems provide processes with multiple threads of control.We will present a discussion of the principles of threading along with its benefits followed by multi-threading models.We will then discuss Thread Libraries and in this section, we’ll discuss Pthreads and Java threads. We will also look at some code here.We will then discuss Threading Issues with related fork() and exec() and clone() system calls, cancelling threads while threads are in execution, the signaling system in Unix, and thread pools.We will look closely how threads are implemented in LinuxWe will not discuss the Win32 API and how it addresses threading in the Windows environment and we will not discuss lightweight processes (LWPs) as this topic is somewhat dated.This is a very important chapter. There will be assignments presented at the conclusion of the chapter.4.3Silberschatz, Galvin and Gagne ©2005Operating System ConceptsOverview of ThreadsOverview of Threads“A thread is a basic unit of CPU utilization;” This means the CPU is dispatched to execute threads.Threads are scheduled for CPU cycles; threads are ‘managed.’Thread within the same process share a code section, data section, and other resources such as open files and signals. (signals discussed later).Idea behind threads is that the process can perform many different activities at the same time (concurrently, of course, on a single CPU) In the past, we have processes with a single thread of control, which means processor can perform one task at a time.Thread management and management of multiple threads of control become serious issues nowadays since most modern desktop and notebook computers have multiple processors (dual core – which is ‘almost’ multiple processors).So what do we mean by multiple threads of control? Why important?4.4Silberschatz, Galvin and Gagne ©2005Operating System ConceptsMultiple Threads of ControlMultiple Threads of ControlMost modern applications are developed as a separate process with several threads of control.This means a number of separate ‘tasks’ that are part of the application can be executed concurrent with other tasks.A word processor might be echoing keystrokes and yet automatically (another thread) might be undertaking styling formatting or checking and doing automatic correcting “at the same time.”If these tasks had to be executed sequentially, performance would be unbearable or simply would not be done thus reducing the overall quality of, say, a document.4.5Silberschatz, Galvin and Gagne ©2005Operating System ConceptsMultiple Threads of ControlMultiple Threads of ControlProcess Creation. We know that process creation is time consuming, and a server creates separate processes when a request for service arrives. Way of doing business before we used threads.So, in order to service a number of perhaps seemingly disjoint tasks concurrently, we need multiple threads which means that we need multiple levels of control! Solution is to have the server create a single thread that ‘listens’ for new requests for service. When received, server creates a thread to service the request.RPCs and Java RMI systems are multi-threaded in that when a server receives a message, the message is serviced by a separate thread, thus providing for concurrent processing.Extending this thinking, kernels are multi-threaded where different threads perform different operating system tasks as well..4.6Silberschatz, Galvin and Gagne ©2005Operating System ConceptsSingle and Multithreaded ProcessesSingle and Multithreaded ProcessesIt is important to note, however, that a multi-threaded process shares resources with its siblings and parent process… Much more later.4.7Silberschatz, Galvin and Gagne ©2005Operating System ConceptsBenefits are ManyBenefits are ManyResponsiveness - Parts of a program can continue running even if parts of it are blocked. Book points out that a multi-threaded web browser could still allow user interaction in one thread while downloading a gif in another thread…Resource Sharing – pros and cons here. By sharing memory or other resources (files, etc.) the threads share the same address space. (there are issues here…)Economy – since threads share resources, it is easier to context-switch threads than context-switching processes. This should be clear. Utilization of MP Architectures – there will be significant increases in performance in a multiprocessor system, where different threads may be running simultaneously (in parallel) on multiple processors.Of course, there’s never ‘a free lunch,’ as we will see later. (There’s always a cost…; nothing this good comes free.  )4.8Silberschatz, Galvin and Gagne ©2005Operating System ConceptsUser ThreadsUser ThreadsWe know that we have threads at both user level and kernel levels.User threads are supported above the kernel and are managed without kernel support.But kernel threads are directly managed by the operating system.Because we have both user threads and kernel threads in the same context, there must be a relationship between the two.Both kinds of threads are vying for he processor!!!We have models whereby user threads are related to kernel threads.Many


View Full Document
Download Chapter 4.1: Threads
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 4.1: Threads and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 4.1: Threads 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?