Threads Flashcards
What two things does a process have in a typical operating system?
Address space
Single thread of control
Where do threads come in?
When you separate the idea of resource grouping and execution
Describe the way of thinking about a process as a bundle.
A process having address space, resources, alarms, handlers, status information. Single process = easy control.
Describe a thread in one line.
Threads are the entities scheduled for execution on the CPU
What do threads allow?
Threads allow multiple executions to take place in the same process environment, largely independent of each other.
How do threads run on a single CPI?
The threads take turns running
If three threads are running from different processes, what illusion is provided?
That the CPU, despite switching between threads, appears to be working in parallel and multiple processes appear to be being completed.
If different threads in the same process are running, what should you be mindful of?
They are not indepedent of each other.
They share the same address space. They also share the same global variables.
This means thread one could be working, the CPU switches to handle thread two and thread two could overwrite the data that thread one had been working on.
Why should the possibility of threads overwriting each not matter?
Because the threads are created in the user space and thus it becomes the user’s concern to ensure the threads work with, rather than in competition against, each other.
What’s the overall goal of threads?
The ability for multiple executions to share a set of resources.
What three states can a thread be in?
Running
Ready
Blocked
Give an example of how a thread could be blocked.
If a thread performs a system call to read data from the keyboard. It is blocked until an action is performed on the keyboard.
What do threads share across a process?
Address space
Global variables
Open files
Signals
What is unique per thread
program counter
registers
stack
state
What is the typical initialisation for a thread for multithreading?
Processes normally start with single thread.
That thread can create new threads.
A parameter is passed to a command that specifies a procedure.
All new threads in same address space.
Sometimes threads are hierarchical. This is rare.