CS代写 COMP3231/COMP9201/COMP3891/COMP9283

12/04/2022, 09:18 Exam/Processes and Threads – COMP3231/COMP9201/COMP3891/COMP9283
Processes and Threads
1. Processes and Threads
1. Describe the three state process model, describe

Copyright By PowCoder代写 加微信 powcoder

what transitions are valid between the three states, and describe an event that might cause such a transition.
2. Multi-programming (or multi-tasking) enables more than a single process to apparently execute simultaneously. How is this achieved on a uniprocessor?
3. What is a process? What are attributes of a process?
4. What is the function of the ready queue?
5. What is the relationship between threads and
processes?
6. Describe how a multi-threaded application can
be supported by a user-level threads package. It may be helpful to consider (and draw) the components of such a package, and the function they perform.
7. Name some advantages and disadvantages of user-level threads.
8. Why are user-level threads packages generally cooperatively scheduled?
9. List the advantages and disadvantages of supporting multi-threaded applications with kernel-level threads.
10. Describe the sequence of steps that occur when a timer interrupt occurs that eventually results in a context switch to another application.
11. Context switching between two threads of execution within the operating system is usually performed by a small assembly language function. In general terms, what does this small function do internally?
Describe the three state process model, describe what transitions are valid between the three states, and describe an event that might cause such a transition.
Process states:
running ready blocked
Transitions:
Running to blocked: Process may block on an IO request.
Running to ready: Process has reached the end of its timeslice or a higher priority thread has been unblocked.
Blocked to ready: Process may have been waiting on an IO request that has now been completed.
https://wiki.cse.unsw.edu.au/cs3231cgi/Exam/Processes and Threads 1/5

12/04/2022, 09:18 Exam/Processes and Threads – COMP3231/COMP9201/COMP3891/COMP9283
Ready to running: This is the highest priority process so the scheduler has chosen it to run in the next timeslice.
Multi-programming (or multi-tasking) enables more than a single process to apparently execute simultaneously. How is this achieved on a uniprocessor?
Preemptive multitasking is achieved by rapidly context switching between processes. Each process is given a window of time to execute, called a ‘timeslice’. The processor then gets interrupted by a timer, which causes it to context switch to another process, which will run until it blocks, or until the next tick. By switching rapidly enough, it creates the illusion that several processes are running simultaneously.
Cooperative multitasking is achieved by having every process yield occasionally, such that other processes can run.
What is a process? What are attributes of a process?
A process is one or more threads of execution that exist in a single virtual memory space. A process has it’s own set of file descriptors, VM space, timekeeping data, pwd, (maybe some other stuff)
1. a program in execution
2. an instance of running program
3. an owner of the resource allocated to program execution 4. a task or a job
5. emcompass one or more threads
Attributes of a process:
Address space
Open files – (could be argued are part of resources) Process ID
Process group
Parent process
Signals and signal handlers
Attributes of threads:
Scheduling parameters Registers
Program counter (PC) Program status word Stack pointer (SP) Thread state
If the OS does not support multi-threaded applications, then thread attributes become process attributes.
What is the function of the ready queue?
The ready queue stores threads that aren’t currently running that are capable of resuming execution. There may be several ready queues for each priority level, depending on the scheduling algorithm. The scheduler consults the ready queue to determine which
https://wiki.cse.unsw.edu.au/cs3231cgi/Exam/Processes and Threads 2/5

12/04/2022, 09:18 Exam/Processes and Threads – COMP3231/COMP9201/COMP3891/COMP9283
process/thread to run next. As the name suggests, the ready queue is a queue, in order to schedule fairly.
What is the relationship between threads and processes?
A process is a container for threads, which has it’s own memory space. A process may contain one or more threads, which share that memory space, all of the file descriptors and other attributes. The threads are the units of execution within the process, they possess a register set, stack, program counter, and scheduling attributes – per thread.
Describe how a multi-threaded application can be supported by a user-level threads package. It may be helpful to consider (and draw) the components of such a package, and the function they perform.
From the kernel’s perspective, each process has its own address space, file descriptors, etc and one thread of execution. To support multiple threads at user-level, the process contains code to create, destroy, schedule and synchronise user-level threads. This multiplexes many user-level threads onto the single kernel thread, all managed within the process. The scheduler can run any scheduling algorithms, and is independent of the kernel’s scheduler.
Components:
Thread control block (TCB): stores information used by the scheduler and queues about a thread.
Ready queue: stores threads that are unblocked and are candidates to run next.
Blocked queue: stores threads that can’t progress until some event occurs.
Scheduler: chooses which thread from the ready queue to run next.
Name some advantages and disadvantages of user-level threads.
Advantages:
Can use a scheduling algorithm that is customised for the process. Faster as they don’t need to trap to kernel space.
Can be implemented on any OS.
Can create and use a large number of threads via virtual memory.
Disadvantages:
Threads must be cooperative and manually yield to avoid monopolising the process. This can complicate application development.
User-level threads that block in the kernel can’t be switched out by the user-level scheduler for another user-level thread.
Cannot take advantage of multiple CPUs, as the OS cannot dispatch threads to different processors since the OS only sees 1 process with 1 thread.
Why are user-level threads packages generally cooperatively scheduled?
https://wiki.cse.unsw.edu.au/cs3231cgi/Exam/Processes and Threads 3/5

12/04/2022, 09:18 Exam/Processes and Threads – COMP3231/COMP9201/COMP3891/COMP9283
User-level schedulers generally don’t have access to timer interrupts at a sufficiently small interval to give the illusion of parallelism.
List the advantages and disadvantages of supporting multi- threaded applications with kernel-level threads.
Advantages
Scheduler can be preemptive, which ensures that no single process monopolises the system and allows programs to be written without yields
Can run different thread when one thread blocks in the kernel, allowing the OS to overlap IO with computation
Can take advantage of multiprocessors Disadvantages
Code is less portable since it requires OS support
Cannot choose the scheduling algorithm
Thread management (create, delete, etc.) is more expensive as it requires system calls
Describe the sequence of steps that occur when a timer interrupt occurs that eventually results in a context switch to another application.
See the answers to the week 5 tutorial.
Thread 1 running happily
Timer tick
Trap into kernel space
switch to kernel stack for thread 1 thread 1 user registers stored
find next thread to run (named thread 2) from scheduler
context switch to thread 2 (change to its kernel stack, make its thread control current, flush tlb)
thread 2 user registers loaded
warp into thread 2
thread 2 running happily
Context switching between two threads of execution within the operating system is usually performed by a small assembly language function. In general terms, what does this small function do internally?
For a real example of such a function, look at switchframe_switch() in OS/161. In general, the assembly language context switch code:
Saves return address (RA), global pointer (GP), local subroutine registers and stack pointer (SP) to the old thread’s thread control block (TCB)
Restores corresponding registers for the new thread
Loads SP from the new thread’s TCB
Jumps to RA from the new thread’s TCB
https://wiki.cse.unsw.edu.au/cs3231cgi/Exam/Processes and Threads 4/5

12/04/2022, 09:18 Exam/Processes and Threads – COMP3231/COMP9201/COMP3891/COMP9283
Exam/Processes and Threads (last edited 2019-05-11 16:28:35 by MarkSonnenschein)
https://wiki.cse.unsw.edu.au/cs3231cgi/Exam/Processes and Threads 5/5

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com