SlideServe
Menu
Préférences
© SlideServe · v2026

CHAPTER 5: THREADS ( 线程 )

papina avatar
18 diapositives · 416 Views · Oct 23, 2014

CHAPTER 5: THREADS ( 线程 ). Overview Multithreading Models (多线程模型) Thread Implementation Issues (线程实现事项) Pthreads Solaris 2 Threads W2K Threads Linux Threads Java Threads. OVERVIEW. Lightweight process (LWP, thread) heavyweight process. Overview: Motivation.

CHAPTER 5: THREADS ( 线程 ) - slide 1
01 / 18CHAPTER 5: THREADS ( 线程 )
1 / 17

Télécharger la présentation

CHAPTER 5: THREADS ( 线程 )
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CHAPTER 5: THREADS (线程) • Overview • Multithreading Models (多线程模型) • Thread Implementation Issues (线程实现事项) • Pthreads • Solaris 2 Threads • W2K Threads • Linux Threads • Java Threads

  2. OVERVIEW • Lightweight process (LWP, thread) • heavyweight process

  3. Overview: Motivation • Examples of multithreaded program: • web browser, word processor, • database server, web server. • Benefits • Responsiveness, • Resource Sharing, • Economy(creation 30:1, context switching 5:1), • Utilization of MP Architectures.

  4. Overview: User and Kernel Threads • User Threads • Provided by a thread library at the user level, • Fast/Blocking, • POSIX Pthreads, Mach C-threads, Solaris UI-threads. • Kernel Threads • Provided by the OS directly, • Fast/Nonblocking, • Linux Solaris2, Windows, BeOS.

  5. MULTITHREADING MODELS • Many-to-one model • One-to-one model • Many-to-many model

  6. Multithreading models: Many-to-one model • Many user-level threads mapped to single kernel thread. • Used on systems that do not support kernel threads. • Example: Green threads for Solaris2.

  7. Multithreading models: one-to-one model • Each user-level thread maps to kernel thread. • Examples: Windows 95/98/NT/2000, OS/2.

  8. Multithreading models: 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. • Examples: Solaris 2, IRX, HP-UX.

  9. THREAD IMPLEMENTATION ISSUES • The fork and exec system calls • Two versions of fork • To duplicate all the threads • To duplicate the calling thread only • No change for exec. • Thread cancellation. • Asynchronous cancellation: one thread immediately terminates the target thread • Deferred cancellation: the target thread can periodically check if it should terminate, allowing the target thread an opportunity to terminate itself in an orderly fashion.

  10. Thread implementation issues • Signal handling • Signal is generated by the occurrence of a particular event. A generated signal is delivered to a process. Once delivered, the signal must be handled. • Two types: synchronous or asynchronous signals. • Signal handling: default or user-defined signal handler. • Where should a signal be delivered in multithreaded. programs? • To the thread to which the signal applies • To every thread in the process • To certain threads in the process • Assign a specific thread to thread all signals for the process.

  11. Thread implementation issues • How to handle a new request for a multithreaded server • To create a new thread • Time consuming to create. • No limit on the number of new threads. • Thread pool: To create a number of threads at the process startup and place them into a pool, where they sit and wait for work. • Thread specific data • Specific data, • Win32, Pthreads, Java Threads.

  12. PTHREADS • A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization. • API specifies behavior of the thread library, implementation is up to development of the library. • Common in UNIX operating systems. • A multithreaded C program using the Pthread API.

  13. SOLARIS 2 THREADS User-level threads LWP (LightWeight Process) Kernel threads

  14. Solaris 2 threads A process in Solaris 2

  15. WINDOW 2000 THREADS • Implements the one-to-one mapping. • Each thread contains - a thread id - register set - separate user and kernel stacks - private data storage area • Each thread includes three primary data structures • ETHREAD (executive thread block) • KTHREAD (kernel thread block) • TEB (thread environment block)

  16. LINUX THREADS • Linux refers to them as tasks rather than threads. • Thread creation is done through clone() system call. • Clone() allows a child task to share the associated data structures of the parent task (process). • Fork() allows a child task to have a copy of all the associated data structures of the parent task. • Why the address space sharing is possible?

  17. JAVA THREADS • Java threads may be created by: • Extending Thread class • Implementing the Runnable interface • Java threads are managed by the JVM. • Java threads are mapped to the underlying host operating system. • An example using Java threads.

  18. Homework • 5.1 • 5.2 • 5.3 • 5.4/5.5 • 5.8/5.9