tags:
- article
- operating-system
source: https://www.personal.kent.edu/%7Ermuhamma/OpSystems/Myos/threads.htm
created: 2024-12-15
Where must threads be executed?
Threads must be executed within a process.
What is the difference between processes and threads?
The difference between processes and threads is that:
- Processes are used to group resources together.
- Threads are entities scheduled for execution on the CPU.
What is a thread?
A thread is a single sequence stream within a process.What are threads often called since they have some of the properties of processes?
Since threads have some of the properties of processes, they are often called lightweight processes.What do threads allow for?
Threads allow for multiple executions of streams.What are threads often used for?
Threads are often used for improving application runtime through parallelism.What does the CPU do if a process has multiple threads?
If a process has multiple threads, the CPU rapidly switches back and forth among the threads which gives the illusion they're running in parallel.What can a thread be in much like a process?
Much like a process, a thread can be in any of several states.What are four states that a thread can be in?
Four states that a thread can be in include:
- Running.
- Blocked.
- Ready.
- Terminated.
Each thread has its own ... since they will generally call different procedures and thus have a different ... ...
Each thread has its own stack since they will generally call different procedures and thus have a different execution history.What are the basic units of CPU utilization on operating systems with threading capabilities?
On operating systems with threading capabilities, the basic unit of CPU utilization are threads.What three things does a thread consist of?
The three things a thread consists of are:
- A Program Counter (PC).
- A register set.
- A stack space.
Are threads independent from each other like processes?
No, threads aren't independent from each other like processes.What three things do threads share with each other?
The three things threads share with each other are:
- Their code sections.
- Their data sections.
- OS resources like open files and signals.
What are four ways in which threads are similar to processes?
Four ways in which threads are similar to processes are that:
What are four ways in which threads are different from processes?
Four ways in which threads are different from processes are:
What are three reasons why you would use threads in designing operating systems?
Three reasons why you would use threads in designing operating systems are:
What are three reasons why threads are cheap on resources?
Three reasons why threads are cheap on resources are:
What is the drawback with threads since they are so cheap?
Since threads are so cheap, the drawback with them is that there's no protection between them.
What are user-level threads?
User-level threads are threads implemented with user-level libraries rather than system calls.
Does thread switching between user-level threads interrupt the operating system or kernel?
No, thread switching between user-level threads doesn't interrupt the operating system or the kernel.How does the kernel manage processes with user-level threads?
The kernel manages processes with user-level threads as if they were single-threaded processes.What are four advantages of user-level threads?
Four advantages of user-level threads are that:
- They don't require modification to the operating system.
- They're simple to represent - Each thread is represented by a PC, registers, stack, and a small control block all stored in the process's address space.
- They're simple to manage - Creating a thread, switching between threads, and synchronizing threads can all be done without intervention from the kernel.
- They're fast and efficient - Switching isn't that much more expensive than a procedure call.
What are four disadvantages of user-level threads?
Four disadvantages of user-level threads are that:
- They lack coordination with the kernel - The whole process gets one time slice regardless of the number of threads and it's up to each to relinquish control to other threads.
- They require non-blocking system calls (via a multithreaded kernel) - Otherwise, the entire process would be blocked by the kernel even if there are runnable threads still in the process.
What are kernel-level threads?
Kernel-level threads are threads which the kernel knows about and manages.
Is a runtime system needed with kernel-level threads?
No, a runtime system isn't needed with kernel-level threads.What does the kernel have in place of the thread table within each process?
In place of the thread table within each process, the kernel has a thread table which keeps track of every thread in the system.What does the kernel provide for programs wanting to use kernel-level threads?
For programs wanting to use kernel-level threads, the kernel provides system calls to create and manage threads.What are two advantages of kernel-level threads?
Two advantages of kernel-level threads are that:
- They can be accounted for by the scheduler when deciding to give more time to a process - Since the kernel knows about every thread on the system, more time can be given to processes with more threads.
- They're especially good for applications which frequently block.
What are two disadvantages of kernel-level threads?
Two disadvantages of kernel-level threads are:
- They're slow and inefficient.
- Each one requires a full Thread Control Block (TCB) to maintain information about it - This causes significant overhead and increased kernel complexity.
What are two advantages of using threads over multiple processes?
Two advantages of using threads over multiple processes are that:
What are two disadvantages of using threads over multiple processes?
Two disadvantages of using threads over multiple processes are that:
What's an example of a program that would benefit from threads?
An example of a program that would benefit from threads is a proxy server that needs to process requests from a number of computers on a LAN.
What type of program generally benefits from threads?
The type of program that generally benefits from threads is any program that has to do more than one task at a time.
What type of program generally doesn't benefit from threads?
The type of program that generally doesn't benefit from threads is any program that has sequential tasks which can't be divided into parallel tasks.
How does the creation of a process differ from the creation of a thread?
The creation of a process differs from the creation of a thread in that the resources that would be shared between threads need to be explicitly created for each process.
Why is creating a process more costly than creating a thread?
Creating a process is more costly than creating a thread because processes can't share resources with one another in the same way that threads can.
What ensures that each process on a machine with multiple processors gets a fair share of the CPU and how?
On a machine with multiple processors, a hardware clock ensures each process gets a fair share of the CPU by generating interrupts periodically.
What do periodic interrupts from the hardware clock allow the operating system to do?
Periodic interrupts from the hardware clock allow the operating system to schedule all processes in main memory using a scheduling algorithm so that they run on the CPU at equal intervals.What does the interrupt handler do when a clock interrupt occurs?
When a clock interrupt occurs, the interrupt handler checks how much time the current running process has used.What does the CPU scheduling algorithm in the kernel do if the current running process has used up its entire time slice?
If the current running process has used up its entire time slice, the CPU scheduling algorithm in the kernel picks a different process to run.What is each switch of the CPU from one process to another called?
Each switch of the CPU from one process to another is called a context switch.
What are the two major steps in context switching?
The two major steps in context switching are:
How often do context switches occur on a multiprogrammed uniprocessor system?
On a multiprogrammed uniprocessor system, context switches occur frequently enough so that all processes appear to be running concurrently.
What can the operating system do if a process has more than one kernel-level thread?
If a process has more than one kernel-level thread, the operating system can use context switching to schedule the threads so they appear to execute in parallel.What must the programmer do if a process has more than one user-level thread?
If a process has more than one user-level thread, the programmer must yield the CPU frequently enough in each thread so that all threads in the process can make progress.
...
Context switching among processes is ...
Context switching among processes is expensive.
What must be saved before a process can be switched?
Before a process can be switched, its Process Control Block (PCB) must be saved.What information does the Process Control Block (PCB) consist of?
The information that the PCB consists of includes:
- The process state.
- The PC.
- The values of the different registers.
- The CPU scheduling information for the process.
- Memory management information regarding the process.
- Possible accounting information for the process.
- I/O status information for the process.
...