Threads Flashcards
What is a thread/process represented by? And what is the structure of this representation?
a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system.
It is represented by a special data structure, called the thread control block (TCB). It contains relevant information about the thread:
- Thread characteristics: thread ID, program name
- State information: instruction counter, stack pointer, register contents
- Management data: Priority, rights, statistics
What are the data structures used to store and manage the TCBs?
Single scalars, static long array, variably long linked list, tree, inverted table, ..
How to efficiently manage multiple TCBs?
Form subsets of TCBs with regards to important attribute values (such as grouping threads of the same state together)
What is the difference between static and dynamic OSs handling threads?
In static OSs, all threads are known in advance and are statically defined. TCBs are declared as program variables and are used for a specific application and are all generated by a configuration program once.
In dynamic OSs, the threads are created and deleted by kernel operations (create_thread (id, initial values) which create a TCB and initialize the thread and delete_thread(id, final values) which return the final values and delete the TCB).
What is a thread’s address space?
A logical address space of a thread is the space of its valid addresses, which it can access. Relative addressing and address translation (using the MMU) allow to have an arbitrary number of logical address spaces that can be mapped to physical address space, leading to mutual protection of address spaces.
What is a Unix process?
It is an address space that contains at least one thread. So we use the term thread directly.
What is thread switching?
It means that the processor stops executing the current thread (its instruction sequence) and continues with the execution of another thread.
What is switching by jumping?
It is where we insert a jump instruction directly into the thread that jumps into another thread. This is however very inflexible and applicable only in very special cases.
Why is thread switching costly?
Because we have to memorize the continuation address in the interrupted thread, selection of the next thread. And the processor must hold on to essential parts of the interrupted thread description that must not get lost (during a register reload).
Memorizing continuation address
Store the address of the next instruction of the interrupted thread to be executed in the interrupted thread in a dedicated variable called ni (next instruction) of the TCB
What are the criteria for selecting the next thread?
Number of threads, order of arrival, priority of each thread (urgency).
Describe simple next thread selection with priority.
Threads are ordered with regards to their execution order or priority. Newly arriving threads are inserted into the priority sequence according to the chosen order. The threads can be organized in a priority queue with two dimensions where there are groups of equal priority.
What is a processor register in relation to threads?
Threads use arithmetic registers of the processor to store intermediate results.
What happens to the register when switching thread by jump?
Its content will be lost (overwritten) so switch by jump can only be used when the contents of the register will no longer needed and the new thread does not expect valid register contents.
What is a thread context?
It is the complete thread specific information that is stored in the processor registers (content of arithmetic registers, index registers, processor state, contents of address registers, segment tables, access control information, etc..)