Mapa mental
Threads
Conteúdo do mapa
Threads
Benefits
- Responsiveness
- User interaction can be run in different threads
- Resource Sharing
- Threads of same process share address space
- Used shared variables to communicate (more efficient than message passing)
- Threads of same process share address space
- Economy
- Smaller memory footprint
- Scalability
- Make use of parallel processing
- Reduce progamming complexity
- Responsiveness
Concurrent and parallel execution
Definition
- Thread is an execution state of a process
User threads
- Thread management done by user-level thread library
- POSIX
- WIN32
- Java
- Thread management done by user-level thread library
Threading modes
- Kernel may not support multi-threaded processes
- Can still implement threading in user threads
- Threading models for mapping user threads to kernel threads
- Many-to-one
- Many user-threads mapped to single kernel thread
- Useful if kernel doesn't support threads
- Problem if one user thread calls blocking kernel function
- Could block all other threads (whole process)
- Solution: replace blocking calls with non-blocking calls and schedule threads in user space
- Shift kernel work to user space
- Solution: replace blocking calls with non-blocking calls and schedule threads in user space
- Could block all other threads (whole process)
- Many user-threads mapped to single kernel thread
- One-to-one
- Each user-level threads maps to one kernel thread
- Context switch overhead for switching between threads
- Overhead not as big as process switching
- Switching less data - page tables / memory shared between threads
- Overhead not as big as process switching
- Context switch overhead for switching between threads
- Each user-level threads maps to one kernel thread
- Many-to-many
- Many user threads mapped to many kernel threads
- Two-level model
- Can bind user thread directly to kernel thread
- Many-to-one
- Kernel may not support multi-threaded processes
Thread cancellation
- Asynchronous cancellation
- Terminates thread immediately - useful as last resort
- Deferred cancellation
- Target thread allowed to periodically check if it should be cancelled
- Cleaner - thread can perform clean up (closing files)
- Target thread allowed to periodically check if it should be cancelled
- Asynchronous cancellation
Signal handling
- Used to notify processes that a particular event has occurred
- Signal handler used to process signals
- Signal generated by event
- Signal delivered to a process
- Signal handled by some function
- Signal delivered to a process
- More complex in multi-threaded processes
- Do you act on processes or individual threads?
- Can deliver signal to thread to which signal applies
- Can deliver signal to every thread in the process (kill signal)
- Can deliver signal to certain threads
- Can assign specific thread to receive all signals for the process
- Signal generated by event
Thread pools
- Waste a lot of processing by creating / destroying threads
- Solution: Pre-create a number of threads in a pool - threads await work
- If no threads are free then block
- Advantages
- Slightly faster to service new request using an existing thread (reduces overhead)
- Allows number of threads to be bound to size of the pool - ensures some level of service
- Control degree on concurrency
- Guarantee throughput
- Eliminates thrashing
- Control degree on concurrency
- Solution: Pre-create a number of threads in a pool - threads await work
- Waste a lot of processing by creating / destroying threads
Informações
- Descrição
- Masters Computer Science (OS) Mapa Mental sobre Threads, criado por Ar B em 27-04-2016.
- Criado por
- Ar B
- Visualizações
- 1
- Avaliação