* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Abstract View of System Components
Mobile operating system wikipedia , lookup
Library (computing) wikipedia , lookup
Plan 9 from Bell Labs wikipedia , lookup
Burroughs MCP wikipedia , lookup
Copland (operating system) wikipedia , lookup
Unix security wikipedia , lookup
Distributed operating system wikipedia , lookup
Spring (operating system) wikipedia , lookup
Security-focused operating system wikipedia , lookup
Chapter 5: Threads • Overview • Multithreading Models & Issues Read Chapter 5 pages 129-135 1 A Thread (Lightweight Process, LWP) • A (traditional/ heavyweight) process has a single thread (of control). • Modern operating systems allow a process to contain multiple threads of control. • Each thread, is defined by its thread ID, program counter, register set & stack (for temporary data). • A thread shares with other threads of the same process its code section, data section, open files & other operating system resources. 2 Multithreaded Applications • Many applications are best executed as a single process with several threads of control • Multithreading: single program composed of a number of different concurrent activities 3 Example Multithreaded Applications • Web browser: – A thread displays information – A thread retrieves data from the network • A Web Server: – A thread to listen for client requests – A thread to service each request • Word Processor: – – – – Thread ONE: displays graphics Thread TWO: reads keystrokes Thread THREE: performs spelling and grammar checking Thread FOUR: …. 4 Single and Multithreaded Processes 5 Benefits of Multithreaded Programming • Responsiveness e.g. a multithreaded web browser allows user interaction in one thread and downloads an image in another thread • Resource Sharing threads share memory and other process resources 6 Benefits of Multithreaded Programming (continued) • Economy: – Creation is 30 times slower for a process than a thread – Context switching is 5 times slower for a process than a thread • More Efficient Utilization of Multiprocessor Architectures – threads run in parallel on different processors 7 Thread State • Shared state: – Global variables – Heap variables • Private state: – Stack variables – Registers • When thread switch occurs, OS needs to save and restore private state 8 User Threads • In user space and without kernel intervention, the library provides support for thread – Creation – Scheduling – Management • Thread management done by user-level threads library • User threads are fast to create and manage 9 Example User Threads • Solaris threads: Sun Microsystems proprietary version of threads. Not portable. • Pthreads – An Application Programming Interface, (API), standard for thread creation and synchronization specified by the IEEE Portable Operating Systems Interface, POSIX in 1995. – API specifies behavior of the thread library, implementation is up to development of the library. – Common in UNIX operating systems. – Pthreads are defined as a set of C language programming types and procedure calls, implemented with a pthread.h header/include file and a thread library. 10 Kernel Threads • Kernel performs thread – Creation – Scheduling – Management • In a MP (multiprocessing) environment, the kernel schedules threads on different processors • Example operating systems with kernel threads: - Windows 95/98/NT/2000 - Solaris - Linux 11 Multithreading Models • Many-to-One • One-to-One • Many-to-Many 12 Many-to-One • Many user-level threads mapped to single kernel thread. • One user thread at a time can access the kernel – Not useful for multiprocessing • Used on systems that do not support kernel threads. 13 Many-to-One Model 14 One-to-One • Each user-level thread maps to a kernel thread. • Allows another thread to run when a thread makes a blocking system call (more concurrency than many to 1) • Allows multiple threads to run in parallel on multiprocessors • Drawback: Creating a user thread requires creating a the corresponding kernel thread – To reduce overhead, restrict the number of threads supported by the system • Examples - Windows 95/98/NT/2000 - OS/2 15 One-to-one Model 16 Many-to-Many Model • Allows many user level threads to be multiplexed to a smaller or equal number of kernel threads. • Allows the operating system to create a sufficient number of kernel threads. • Solaris 2 • Windows NT/2000 with the ThreadFiber package 17 Many-to-Many Model 18