vault backup: 2025-04-21 22:49:53
This commit is contained in:
@ -190,8 +190,34 @@ A light-weight process.
|
||||
- **Kernel Threads**
|
||||
- Managed by OS
|
||||
|
||||
### Relationship modles
|
||||
*
|
||||
### Relationship models
|
||||
#### Many-to-one
|
||||
|
||||
* User-level threads to one kernel treads
|
||||
* Management done by thread library in user space
|
||||
* The entire process blocks whenever a thread makes a blocking sycalls
|
||||
* Only **one** thread can access the kernel at a time (you can't run multiple threads in parallel on multiprocessors)
|
||||
|
||||
#### One-to-one
|
||||
Each user thread is mapped to a kernel thread
|
||||
- Provides more concurrency
|
||||
Unfortunately:
|
||||
- Creating a user thread requires creating the corresponding kernel thread
|
||||
- Overhead of creating kernel threads retricts the number of threads
|
||||
|
||||
|
||||
#### Many-to-many
|
||||
Multiplexes many user threads to a $\leq$ number of kernel threads.
|
||||
|
||||
- Allows creation of however many threads the user wants
|
||||
- The kernel can schedule another thread for execution whenever a thread performs a blocking system call
|
||||
|
||||
|
||||
#### Fork-join
|
||||
Parent creates forks (children threads) and then waits for the children to terminate, joining with them, at which point it can retrieve and combine results.
|
||||
|
||||
This is also called **synchronous threading**. Parent **cannot** continue until the work has been completed.
|
||||
|
||||
|
||||
[^1]: A batch job is a scheduled task or a set of commands that are executed without manual intervention - **cron**
|
||||
|
||||
@ -199,3 +225,21 @@ A light-weight process.
|
||||
|
||||
[^3]: sequence of programmed instructions that can be managed independently by a scheduler within a computer program
|
||||
|
||||
|
||||
##### Parallelism
|
||||
|
||||

|
||||
|
||||
|
||||
## Thread pool
|
||||
Issue wih threads:
|
||||
- Overhead when creating
|
||||
- Exhausting system resources
|
||||
Solution: thread pools - creating a number of threads at startup and place them into a pool where they sit and wait for work.
|
||||
|
||||
|
||||
This optimizes everything because:
|
||||
Sharing threads:
|
||||
- If a thread is blocked (e.g., waiting for I/O), it doesn't remain idle; it can be reassigned to another task
|
||||
- Each thread has its own task queue
|
||||
- Whenever a thread finishes its tasks it looks through the other threads' queues and "steals" tasks.
|
||||
|
Reference in New Issue
Block a user