Download presentation
Presentation is loading. Please wait.
1
ThreadsThreads operating systems
2
ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have one or more threads. Each thread has its own * program counter * set of registers * execution stack But, all threads within a process share the same address space the same files, the same signals, and the same child processes! operating systems
3
codedatafilesregistersstack thread single thread process codedatafilesregistersstack thread registersstack thread multiple thread process pc
4
Why Threads? It allows an application to do multiple things at once * Real parallelism with multiple cpu’s * overlap I/O, user interaction with processing * share the same address space Threads are cheaper than processes because they have no resources associated with them. Context switches are cheaper. operating systems
5
Benefits of using threads Responsiveness: One thread can run while another is blocked * Resource sharing Economy: On a Solaris (SUN) O/S Thread creation is 30 times faster than process creation Context switching for a thread is 5 times faster than process context switching Exploitation of multi-processor architectures * Assuming that threads are implemented in the kernel operating systems
6
Implementing Threads There are two approaches to implementing threads, and the differences are quite controversial. Support for threads can be provided either at the user level or by the kernel. Virtually all contemporary operating systems support kernel threads. operating systems
7
Implementing Threads Implementing Threads in User Space user space kernel space process table thread table run-time system process threads thread table run-time system process threads A run-time system provides the interface to manage threads Each process has it’s own thread table No trap to kernel space is needed, no context switch is needed operating systems -- many to One Model --
8
Implementing Threads Implementing Threads in User Space user space kernel space process table thread table run-time system process threads thread table run-time system process threads operating systems Problems: 1. A blocking system call issued in one thread will block all threads in the process. 2. If a page fault occurs in one thread, all threads are blocked while the system pages. 3. Once a thread starts running there is no way to interrupt it. It must give up the cpu voluntarily.
9
Implementing Threads Implementing Threads in the Kernel user space kernel space process table process threads process threads No run time system. Use kernel calls to manage threads Thread table is kept in the kernel Kernel schedules threads, no blocking issues But … system calls are much more expensive than using a run-time system. thread table operating systems -- one to one model --
10
Implementing Threads There is a hybrid approach to thread support used by Linux. user space kernel space process table process threads process threads The kernel has a small set of re-usable threads that it manages. Threads in user space are mapped onto one of the available kernel threads. thread table run-time system thread table run-time system operating systems
11
Thread Libraries Thread libraries provide the programming interface for creating and managing threads. Thread libraries may be implemented completely in user space, or in kernel space.
12
Thread Libraries There are three main thread libraries in use today * POSIX pthreads * win32 threads * Java threads
13
Thread Issues When a thread issues a fork( ) system call, does the new process contain just one thread, or all of the threads of the original process?
14
Thread Issues When a signal occurs, should the signal * be delivered to all threads in the process? * deliver the signal only to the thread to which it applies? * deliver the signal to certain threads in the process? * Assign a specific thread to handle all signals for the process?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.