1 / 14

Chapter 4: Threads

Chapter 4: Threads. Typical Program. Processor utilization?. Without Kernel Support. Why discuss in an OS course Without kernel support: Responsibility on the process Requires a thread manager compiled as part of each multithreaded process Appears single-threaded to OS

rae-fields
Download Presentation

Chapter 4: Threads

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. Chapter 4: Threads

  2. Typical Program • Processor utilization?

  3. Without Kernel Support • Why discuss in an OS course • Without kernel support: • Responsibility on the process • Requires a thread manager • compiled as part of each multithreaded process • Appears single-threaded to OS • Responsibilities of thread manager • Primary control of the process • Determines • Which thread to execute • When to switch to another thread Threads Thread Manager Operating System

  4. Conceptually, no kernel support is many-to-one Many user-level threads mapped to single kernel thread Examples: Solaris Green Threads GNU Portable Threads Many-to-One Model Known as User Level Threading

  5. When an application requests I/O it is put in the waiting queue Even if thread manager suspends a thread just before an I/O request once the TM allows a single I/O request the entire process gets suspended Drawback of User Level A single I/O request from any thread causes the entire application to be suspended

  6. Kernel Support • Thread-aware kernel • Can avoid suspending a multi-threaded app on I/O • When I/O complete • Determines if process is running • Informs process of I/O completion Thread aware kernel allows for more efficient use of resources particularly for high I/O applications

  7. Kernel Threads • Idea of threads has even been extended to the OS, itself • Thread models • Many-to-One • One-to-One • Many-to-Many • OS’s that support kernel threads • Windows XP/2000 • Solaris • Linux • Tru64 UNIX • Mac OS X

  8. One-to-One • Each user-level thread maps to kernel thread • Examples • Windows NT/XP/2000 • Linux • Solaris 9 and later • Drawback: must generate a kernel thread for every user thread

  9. Many-to-Many Model • Can generate a kernel thread for each logical task • OS’s that support it • Solaris prior to version 9 • Windows NT/2000 with the ThreadFiber package

  10. Two-level Model • Similar to M:M, except that it allows a user thread to be bound to kernel thread • Examples • IRIX • HP-UX • Tru64 UNIX • Solaris 8 and earlier

  11. Thread Libraries • Three primary thread libraries: • POSIX Pthreads • Available with and without kernel • Win32 threads • Kernel support • Java threads • Kernel support depends upon host system • JVM written and compiled for each host

  12. Example • Posix threads example #include <pthread.h> pthread_tmyThread; pthread_create( &myThread, pointerToFunction); pthread_join( myThread);

  13. Parallel calculation example • Create an array of threads • Put jobs in a list • Create a thread for each job • Each thread watches a list of available servers • When a server becomes available, takes ownership of the server, and sends the job to the server • When complete, thread puts job in completed list, and puts server in available server list Completed Jobs Pending Jobs Servers

  14. End of Chapter 4

More Related