Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin, and Gagne  1999 5.1 Applied Operating System Concepts Module 5: Threads Benefits User and Kernel Threads Multithreading Models Solaris.

Similar presentations


Presentation on theme: "Silberschatz, Galvin, and Gagne  1999 5.1 Applied Operating System Concepts Module 5: Threads Benefits User and Kernel Threads Multithreading Models Solaris."— Presentation transcript:

1 Silberschatz, Galvin, and Gagne  1999 5.1 Applied Operating System Concepts Module 5: Threads Benefits User and Kernel Threads Multithreading Models Solaris 2 Threads Java Threads

2 Silberschatz, Galvin, and Gagne  1999 5.2 Applied Operating System Concepts Responsiveness Resource Sharing Economy Utilization of MP Architectures Benefits

3 Silberschatz, Galvin, and Gagne  1999 5.3 Applied Operating System Concepts Single and Multithreaded Processes

4 Silberschatz, Galvin, and Gagne  1999 5.4 Applied Operating System Concepts User Threads Thread Management Done by User-Level Threads Library Examples - POSIX Pthreads - Mach C-threads - Solaris threads

5 Silberschatz, Galvin, and Gagne  1999 5.5 Applied Operating System Concepts Kernel Threads Supported by the Kernel Examples - Windows 95/98/NT - Solaris - Digital UNIX

6 Silberschatz, Galvin, and Gagne  1999 5.6 Applied Operating System Concepts Multithreading Models Many-to-One One-to-One Many-to-Many

7 Silberschatz, Galvin, and Gagne  1999 5.7 Applied Operating System Concepts Many-to-One Many User-Level Threads Mapped to Single Kernel Thread. Used on Systems That Do Not Support Kernel Threads.

8 Silberschatz, Galvin, and Gagne  1999 5.8 Applied Operating System Concepts Many-to-one Model

9 Silberschatz, Galvin, and Gagne  1999 5.9 Applied Operating System Concepts One-to-One Each User-Level Thread Maps to Kernel Thread. Examples - Windows 95/98/NT - OS/2

10 Silberschatz, Galvin, and Gagne  1999 5.10 Applied Operating System Concepts One-to-one Model

11 Silberschatz, Galvin, and Gagne  1999 5.11 Applied Operating System Concepts Many-to-many Model

12 Silberschatz, Galvin, and Gagne  1999 5.12 Applied Operating System Concepts Solaris 2 Threads

13 Silberschatz, Galvin, and Gagne  1999 5.13 Applied Operating System Concepts Solaris Process

14 Silberschatz, Galvin, and Gagne  1999 5.14 Applied Operating System Concepts Java Threads Java Threads May be Created by: –Extending Thread class –Implementing the Runnable interface

15 Silberschatz, Galvin, and Gagne  1999 5.15 Applied Operating System Concepts Extending the Thread Class class Worker1 extends Thread { public void run() { System.out.println(“I am a Worker Thread”); }

16 Silberschatz, Galvin, and Gagne  1999 5.16 Applied Operating System Concepts Creating the Thread public class First { public static void main(String args[]) { Worker runner = new Worker1(); runner.start(); System.out.println(“I am the main thread”); }

17 Silberschatz, Galvin, and Gagne  1999 5.17 Applied Operating System Concepts The Runnable Interface public interface Runnable { public abstract void run(); }

18 Silberschatz, Galvin, and Gagne  1999 5.18 Applied Operating System Concepts Implementing the Runnable Interface class Worker2 implements Runnable { public void run() { System.out.println(“I am a Worker Thread”); }

19 Silberschatz, Galvin, and Gagne  1999 5.19 Applied Operating System Concepts Creating the Thread public class Second { public static void main(String args[]) { Runnable runner = new Worker2(); Thread thrd = new Thread(runner); thrd.start(); System.out.println(“I am the main thread”); }

20 Silberschatz, Galvin, and Gagne  1999 5.20 Applied Operating System Concepts Java Thread Management suspend() – suspends execution of the currently running thread. sleep() – puts the currently running thread to sleep for a specified amount of time. resume() – resumes execution of a suspended thread. stop() – stops execution of a thread.

21 Silberschatz, Galvin, and Gagne  1999 5.21 Applied Operating System Concepts Java Thread States

22 Silberschatz, Galvin, and Gagne  1999 5.22 Applied Operating System Concepts Producer Consumer Problem public class Server { public Server() { MessageQueue mailBox = new MessageQueue(); Producer producerThread = new Producer(mailBox); Consumer consumerThread = new Consumer(mailBox); producerThread.start(); consumerThread.start(); } public static void main(String args[]) { Server server = new Server(); }

23 Silberschatz, Galvin, and Gagne  1999 5.23 Applied Operating System Concepts Producer Thread class Producer extends Thread { public Producer(MessageQueue m) { mbox = m; } public void run() { while (true) { // produce an item & enter it into the buffer Date message = new Date(); mbox.send(message); } private MessageQueue mbox; }

24 Silberschatz, Galvin, and Gagne  1999 5.24 Applied Operating System Concepts Consumer Thread class Consumer extends Thread { public Consumer(MessageQueue m) { mbox = m; } public void run() { while (true) { Date message = (Date)mbox.receive(); if (message != null) // consume the message } private MessageQueue mbox; }


Download ppt "Silberschatz, Galvin, and Gagne  1999 5.1 Applied Operating System Concepts Module 5: Threads Benefits User and Kernel Threads Multithreading Models Solaris."

Similar presentations


Ads by Google