1 / 28

Operating System Principles

Operating System Principles. Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University. Chapter 4 Multithreaded Programming. A process With a single thread of control With multiple threads of control

xantha-beck
Download Presentation

Operating System Principles

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. Operating System Principles Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

  2. Chapter 4Multithreaded Programming • A process • With a single thread of control • With multiple threads of control • Multithreaded computer systems • Pthreads • Windows 32 threads • Java thread libraries • Windows XP and Linux • Support at the kernel level Chapter 4 Multithreaded Programming

  3. Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples Summary Exercises Chapter 4Multithreaded Programming Chapter 4 Multithreaded Programming

  4. 4.1 Overview • A thread • A basic unit of CPU utilization • A thread ID • A program counter • A register set • A stack • Called a lightweight process (LWP) • A traditional process has a single thread of control, called a heavyweight process (HWP) Chapter 4 Multithreaded Programming

  5. Single-threaded and Multithreaded processes Chapter 4 Multithreaded Programming

  6. 4.1.1 Motivation • A web browser • One thread display images or text • Another thread retrieves data from the network • A word processor • One thread for displaying graphics • Another thread for reading keystrokes • Third thread for performing spelling and grammar checking Chapter 4 Multithreaded Programming

  7. 4.1.1 Motivation • If new process will perform the same tasks as the existing process, why incur all that overhead? • Process creation is very time-consuming and resource intensive. • Have the server run as a single process that accepts requests. Chapter 4 Multithreaded Programming

  8. 4.1.2 Benefits • Responsiveness • Allow a program to continue even if part of it is blocked or is performing a lengthy operation • Resource sharing • Memory • Different threads all within the same address space • Resources • Economy • More economical to create and context switch threads • Utilization of multiprocessor architectures • Increase concurrency Chapter 4 Multithreaded Programming

  9. Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples Summary Exercises Chapter 4Multithreaded Programming Chapter 4 Multithreaded Programming

  10. 4.2 Multithreading Models • User threads • Implemented by a thread library at the user level • Supported above the kernel • Advantage • Fast to create and manage • Disadvantage • A thread may cause the entire process to block • Examples • POSIX Pthreads • Win32 threads • Java threads Chapter 4 Multithreaded Programming

  11. 4.2 Multithreading Models • Kernel threads • The kernel performs thread creation, scheduling, and management • Supported directly by OS • Advantage • Kernel can schedule another thread when a thread is blocked • Disadvantage • Slow to create and manage • Examples • Windows XP • Linux • Max OS X • Solaris • Tru64 Unix Chapter 4 Multithreaded Programming

  12. 4.2 Multithreading Models • Many systems provide support for both user and kernel threads • Different multithreading models • Many-to-one model • One-to-one model • Many-to-many model Chapter 4 Multithreaded Programming

  13. 4.2.1 Many-to-One Model • Many user-level threads mapped to one kernel thread Chapter 4 Multithreaded Programming

  14. 4.2.1 Many-to-One Model • Advantage • Efficient • Disadvantage • Entire process may block if a thread makes a blocking system call • Unable to run in parallel on multiprocessors • Used on systems that do not support kernel threads • Green threads – a thread library available for Solaris • GNU Portable Threads Chapter 4 Multithreaded Programming

  15. 4.2.2 One-to-One Model • Each user thread mapped to one kernel thread Chapter 4 Multithreaded Programming

  16. 4.2.2 One-to-One Model • Advantage • More concurrency • Disadvantage • Overhead of creating kernel threads can burden the performance of an application • Restrict the number of threads • Example • Linux • Windows operating systems • Windows 95, 98, NT, 2000, and XP Chapter 4 Multithreaded Programming

  17. 4.2.3 Many-to-Many Model • Multiplex many user-level threads to a small or equal number of kernel threads – two-level model Chapter 4 Multithreaded Programming

  18. 4.2.3 Many-to-Many Model • Advantage • Developers can create as many as user threads as wish • More concurrency • Example • IRIX • HP-UX • Tru64 Unix • Solaris prior to version 9 Chapter 4 Multithreaded Programming

  19. Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples Summary Exercises Chapter 4Multithreaded Programming Chapter 4 Multithreaded Programming

  20. 4.3 Thread Libraries • A thread library • Provide the programmer an API for creating and managing threads • Two primary approaches • A user-level library • Entirely in user space, with no kernel support • A local function call in user space • A kernel-level library • Supported by the operating system • A system call to the kernel Chapter 4 Multithreaded Programming

  21. 4.3 Thread Libraries • Three main thread libraries in use • POSIX Pthreads • A specification for thread behavior • not an implementation • Win32 • Java Chapter 4 Multithreaded Programming

  22. Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples Summary Exercises Chapter 4Multithreaded Programming Chapter 4 Multithreaded Programming

  23. Be skipped Chapter 4 Multithreaded Programming

  24. Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples Summary Exercises Chapter 4Multithreaded Programming Chapter 4 Multithreaded Programming

  25. Summary • P.141 to P.142 Chapter 4 Multithreaded Programming

  26. Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples Summary Exercises Chapter 4Multithreaded Programming Chapter 4 Multithreaded Programming

  27. Exercises • 4.3 • 4.4 Chapter 4 Multithreaded Programming

  28. The End

More Related