Operating System Fundamentals
Operating System Fundamentals
1. Provide TWO examples where multithreading provides better performance than a single-threaded solution. A web server that services each request in a separate thread. An interactive GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application and a third thread monitors performance. 2. If an application or function needs to be implemented as a set of related units of execution, describe the FOUR reasons why it is more efficient to do so as a collection of threads rather than a collection of separate processes? It takes far less time to create a new process in an existing process that to create a brand new process. It takes less time to terminate a thread. It takes less time to do control switching between two threads within a same process. Threads sharing the same user address space enable the communication to be done naturally but the communication between processes required supports from the operating system. 3. Describe the FIVE challenges of using thread in operating system. Dividing Activities Examining the application to identify the areas that can be divided into separate tasks that can be executed on different processing unit concurrently. Balance Data Splitting Ensure the divided tasks will perform equal work of equal value. Related to dividing activities, the data to be accessed and manipulated by multiple threads must be divided to run on separate processing unit as well. Data Dependency Testing & Debugging The data accessed by the tasks must be examined for dependencies between two or more tasks. The process of testing and debugging of application that having multiple threads running concurrently is inherently more difficult. 4. Describe the FOUR benefits of using thread in operating system. Responsiveness Allow a program to continue running even if part of it is blocked or is performing a length operation
Threads share the resource of the process which they belong to. Take less resources to create and context-switch between threads is faster than processes. Threads may be running in parallel in multiprocessor system.
5. Describe
the
one-to-one,
many-to-many,
and
two-level
models
in
multithreading. One-to-one model Each user thread maps to kernel thread, this could benefit from multiprocessors system that can execute multiple threads in parallel. Many-to-one model Many user threads mapped to a single kernel thread, only one thread can access a kernel at a time. Many-to-many model Many user threads can be mapped to many kernel threads that the number can be smaller or equal to the user threads. Two-level model Similar to the many-to-many model but a user thread is allowed to be bound to kernel thread. 6. For a heavy loaded server, do you think it is feasible to explicitly create a thread to handle each users request? If you think it is feasible, justify your answer, else, explain why it is not feasible and provide a solution. No. It is not feasible because the server might breakdown due to excessive number of users. It is better to create a thread pool with fixed number of threads, or restricts the total amount of threads that can be created and executed concurrently.