1 / 24

Multithreading Models: Benefits, User and Kernel Threads (100 characters)

Learn the benefits of multithreading, including responsiveness, resource sharing, economy, and utilization of MP architectures. Explore user and kernel threads, as well as different multithreading models like many-to-one, one-to-one, and many-to-many. Examples from Solaris, Windows, and Java. (500 characters)

dhuffaker
Télécharger la présentation

Multithreading Models: Benefits, User and Kernel Threads (100 characters)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 5: Threads • Benefits • User and Kernel Threads • Multithreading Models • Solaris 2 Threads • Java Threads Applied Operating System Concepts

  2. Benefits • Responsiveness • Resource Sharing • Economy • Utilization of MP Architectures Applied Operating System Concepts

  3. Single and Multithreaded Processes Applied Operating System Concepts

  4. User Threads • Thread Management Done by User-Level Threads Library • Examples - POSIX Pthreads - Mach C-threads - Solaris threads Applied Operating System Concepts

  5. Kernel Threads • Supported by the Kernel • Examples - Windows 95/98/NT - Solaris - Digital UNIX Applied Operating System Concepts

  6. Multithreading Models • Many-to-One • One-to-One • Many-to-Many Applied Operating System Concepts

  7. Many-to-One • Many User-Level Threads Mapped to Single Kernel Thread. • Used on Systems That Do Not Support Kernel Threads. Applied Operating System Concepts

  8. Many-to-one Model Applied Operating System Concepts

  9. One-to-One • Each User-Level Thread Maps to Kernel Thread. • Examples - Windows 95/98/NT - OS/2 Applied Operating System Concepts

  10. One-to-one Model Applied Operating System Concepts

  11. Many-to-many Model Applied Operating System Concepts

  12. Solaris 2 Threads Applied Operating System Concepts

  13. Solaris Process Applied Operating System Concepts

  14. Java Threads • Java Threads May be Created by: • Extending Thread class • Implementing the Runnable interface Applied Operating System Concepts

  15. Extending the Thread Class class Worker1 extends Thread { public void run() { System.out.println(“I am a Worker Thread”); } } Applied Operating System Concepts

  16. 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”); } } Applied Operating System Concepts

  17. The Runnable Interface public interface Runnable { public abstract void run(); } Applied Operating System Concepts

  18. Implementing the Runnable Interface class Worker2 implements Runnable { public void run() { System.out.println(“I am a Worker Thread”); } } Applied Operating System Concepts

  19. 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”); } } Applied Operating System Concepts

  20. 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. Applied Operating System Concepts

  21. Java Thread States Applied Operating System Concepts

  22. 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(); } } Applied Operating System Concepts

  23. 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; } Applied Operating System Concepts

  24. 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; } Applied Operating System Concepts

More Related