Presentation on theme: "Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating."— Presentation transcript:
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating threads, and preemptively switches control among (kernel- level) threads. A thread is simply a function that can call other functions.
Multithreading Threads are part of same process and share all process resources: Memory Open Files Global Variables Static Variables Each thread has its own: processor (and math coprocessor) state stack
Lightweight process. Threads share all process resources. State: Thread ID, program counter, register set, and stack. User-level threads and kernel-level threads.
Benefits Performance: Overlap communication/computation Responsiveness: Separate thread to handle user input. Web server spawns separate thread to handle incoming request. Resource Sharing: e.g., one code, data segment. Economy: Much cheaper to create and switch than processes. Utilization of MP Architectures: Assign each thread to a separate processor if available.
User Threads Thread management done by user-level threads library. Advantages: Very fast: Does not involve kernel in creation, scheduling, or switching. Disadvantages: When a thread blocks, whole process blocks.
Kernel Threads Supported by the Kernel. Kernel creates, schedules, and switches threads. Advantage: When one thread blocks, the whole process does not have to block. Thus can overlap I/O and computation. Disadvantage: Slower since kernel is involved.
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. Solaris 2 Windows NT/2000 with the ThreadFiber package
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.