diff options
| author | mo khan <mo@mokhan.ca> | 2021-03-22 20:51:52 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-03-22 20:51:52 -0600 |
| commit | a24b4ec8c6d50f92891c7cda61238ce1abe4f216 (patch) | |
| tree | b9dbcde49384be9297b9530b2d440abe3589bb86 /doc | |
| parent | 491623c9c6eb612eb51d14c0719c8d1f01727320 (diff) | |
Add notes on threads
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/3.md | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -123,4 +123,40 @@ Process Control Block ---------------------- ``` +On Linux this is represented in `struct task_struct` in `<linux/sched.h>`. + ### Threads + +The process model discussed so far has implied that a process is a program that performs a single `thread` +of execution. + +Processes can have multiple threads of execution and thus to perform more than one task at a time. +This is beneficial on multicore systems, where multiple threads can run in parallel. + +On systems that supports threads, the PCB is expanded to include information for each thread. + +### Process Scheduling + +Multiprogramming: have some process running at all times to maximize CPU usage. +Time sharing: switch the CPU among processes so frequently that users can interact with each program while it is running. + +The `process scheduler` selects an available process for program execution on the CPU. +A single-processor system, there will never be more than one running process. The rest will +have to wait until the CPU is free. + +#### Scheduling Queues + +As processes enter the system, they are put into a `job queue`, which consists of all processes in the system. +The processes that are residing in main memory and are ready and waiting to execute are kept in the `ready queue`. +This queue is usually stored as a linked list. +The doubly-linked list contains process control block nodes/structs. Each PCB points to the next PCB in the ready queue. + +The list of processes waiting for a particular I/O device is called a `device queue`. +Each device has its own device queue. + +A new process is initially put in the ready queue. It waits there until it is selected for execution, +or `dispatched`. Once the process is allocated the CPU and is executing, one of the several events could occur: + +* The process could issue an I/O request and then be placed in an I/O queue. +* The process could create a new child process and wait for the child's termination. +* The process could be removed forcibly from the CPU, as a result of an interrupt and be put back in the ready queue. |
