Presentation is loading. Please wait.

Presentation is loading. Please wait.

9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.

Similar presentations


Presentation on theme: "9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides."— Presentation transcript:

1 9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides by Silberschatz, Galvin, and Gagne ©2007 from Operating System Concepts with Java, 7th Edition with some modifications –Also includes material by Dr. Susan Vrbsky from the Computer Science Department at the University of Alabama

2 9/13/20152 Threads A thread (light-weight process) is a single sequential flow of control consisting of a PC (program counter), register set, stack space –Threads share code section, data section, and OS resources (such as files) These items are combined for a task –A task is the execution environment in which threads run consisting of a code section, data section, and OS resources (such as files) A traditional process is a task with one thread (heavy-weight process)

3 9/13/20153 Single & Multithreaded Processes

4 9/13/20154 Examples Multiple threads allow for multiple points of execution –A Web browser may have one thread display text, while another thread retrieves data from a network –A word processor may have one thread handling the user’s keystrokes, and another thread doing the spell check –A Web server may be serving 1,000 different clients with 1,000 different threads

5 9/13/20155 Benefits of Using Threads 1.Responsiveness –An application can do several things as once For example, a browser can use one thread for I/O and another thread to download an image 2.Resource Sharing –Code, data, and other resources are shared Can have multiple threads using the same address space in memory

6 9/13/20156 Benefits of Using Threads 3.Economy –Thread creation is less costly than process creation With the Solaris Operating System of Sun Microsystems, creating a thread is 30 times faster than creating a process, and 5 times faster than context switching 4.Utilization of MP (Multiple Processor) Architectures –Schedule a separate thread on each processor

7 9/13/20157 User and Kernel Threads User threads –Thread management done by user-level threads library. Kernel threads –Threads directly supported by the kernel.

8 9/13/20158 Multithreading Models Mapping user threads to kernel threads 1.Many-to-One 2.One-to-One 3.Many-to-Many

9 9/13/20159 Many-to-One Many user-level threads mapped to a single kernel thread –Efficient, because thread management done by thread library in user space –Cannot take advantage of running multiple threads in parallel on multiprocessors Examples –Solaris Green Threads –GNU Portable Threads

10 9/13/201510 Many-to-One Model

11 9/13/201511 One-to-One Each user-level thread maps to a single kernel thread –Kernel threads can run in parallel on a multiprocessor –Possible to create too many kernel threads and overburden the system Examples –Windows NT/XP/2000 –Linux –Solaris 9 and later

12 9/13/201512 One-to-one Model

13 9/13/201513 Many-to-Many Model Allows many user level threads to be mapped to many kernel threads –Allows the operating system to create a sufficient number of kernel threads –Kernel threads can run in parallel on a multiprocessor Examples –Solaris prior to version 9 –Windows NT/2000 with the ThreadFiber package

14 9/13/201514 Many-to-Many Model

15 9/13/201515 Java Threads Java threads are managed by the JVM (Java Virtual Machine) –The JVM is can be thought of as a software computer that runs inside a hardware computer Java threads may be created by: –Implementing the Runnable interface

16 9/13/201516 Summation Program

17 9/13/201517 Summation Program

18 9/13/201518 Producer-Consumer Program

19 9/13/201519 Producer-Consumer Program

20 9/13/201520 Producer-Consumer Program


Download ppt "9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides."

Similar presentations


Ads by Google