03 Practice Exercise 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

IT2106

Busano, Anna Marie C. BSCPE 211

Practice Exercise
Threads
Objectives:

At the end of the exercise, the students should be able to:

 Discuss the basic functionalities of threads; and


 Deduce the performance implications of multithreading to an operating system.

Instructions:

1. Search for relative studies and/or literature regarding the process and thread concepts of the following
operating systems:
A. Linux OS
 In Linux, processes and threads are the basic units of execution with different roles in
multitasking. A process is an independent program that runs with its own memory space,
resources and execution environment. Each process has a unique process ID (PID) and
processes can spawn child processes to create a hierarchical structure. Threads on the other
hand are small units of execution within a process that share the same memory and
resources, allowing for efficient parallel processing. A process can contain multiple threads,
all running simultaneously. This shared resource model reduces overhead compared to
processes because threads avoid the costly context switches associated with inter-process
communication (IPC). Linux uses both concepts to optimize performance, with the kernel
managing process scheduling and thread execution to achieve concurrency and resource
efficiency.
B. Android OS
 Processes and threads are essential ideas in Android OS for controlling how apps run. In
Android, a process is an instance of an application that runs independently, complete with its
own memory and system resources. In order to maintain stability and security and avoid
interference from other apps, Android apps usually operate in separate processes. Threads
are used to run code simultaneously within a process. While background threads, which are
frequently made with classes like Async Task or Handler Thread, are used for tasks like file
I/O or network activities, the main thread (UI thread) manages user interactions and changes
the user interface. By moving resource-intensive operations off the main thread, this division
guarantees responsive user interfaces. Performance problems can result from improper
handling of threads and processes, including app crashes and slow responsiveness.
2. Then, provide or answer the following for each operating system (Linux and Android):
 Provide a diagram showing the process and thread construct of the operating system. (5 points)
 Briefly explain the diagram that you have provided. (5 points)
-The diagram illustrates the structure of processes and threads within an operating system. Each
process is depicted as having its own memory space, isolating it from other processes. Within each
process, multiple threads are shown sharing the same memory space and resources, such as code,
data, and files. Threads within a process execute concurrently, each having its own execution flow.
The operating system's kernel manages both the processes and threads, distributing tasks across
CPU cores, allowing for parallel execution. This setup improves efficiency and multitasking
capabilities but requires careful management to avoid resource contention and overhead.
 How does the operating system support or implement multithreading? (5 points)
- The operating system supports multithreading by providing mechanisms for thread creation,
scheduling, and synchronization. It allows multiple threads to exist within a single process, sharing
the same memory space but executing independently. The OS manages the scheduling of threads
using time-slicing and prioritization, ensuring that CPU resources are distributed fairly among all
threads. For synchronization, the OS provides primitives like mutexes, semaphores, and condition
variables to coordinate access to shared resources and prevent race conditions. Additionally, the
OS kernel switches between threads rapidly, giving the illusion of parallel execution even on single-
core processors, while multi-core processors allow true parallelism by running multiple threads
simultaneously across different cores. This efficient management of threads allows for concurrent
execution, improving performance and responsiveness in multitasking environments.
 Is it possible to increase the number of threads within processes without affecting the
average response time of this operating system? Why or why not? (5 points)
- Increasing the number of threads within processes can impact the average response time of
the operating system, depending on the system’s resources and how the threads are managed.
While more threads can improve performance by enabling greater parallelism and faster task
completion, they also increase overhead due to context switching, which is the process of saving
and loading thread states. If too many threads are created, the CPU spends more time switching
between threads rather than executing them, leading to longer response times. Additionally,
excessive threads can cause contention for shared resources (e.g., memory, I/O), further
degrading performance. Therefore, without careful thread management and optimal resource
allocation, increasing the number of threads can negatively affect the system's responsiveness,
especially on systems with limited CPU cores or memory.
 What are the possible effects of multithreading in the central processing unit (CPU)
utilization of this operating system? Rationalize your answers. (5 points)
- Multithreading can significantly affect CPU utilization in both positive and negative ways. On
the positive side, multithreading can enhance CPU efficiency by keeping the processor busy with
multiple tasks, especially when one thread is waiting for I/O operations, allowing others to
execute. This leads to better resource utilization and increased throughput, particularly on multi-
core CPUs where true parallel execution of threads can occur. However, excessive multithreading
can cause higher overhead due to frequent context switching, where the CPU has to save and
restore the state of threads, reducing the time spent on actual computation. This can lead to
inefficient CPU usage, as more time is consumed managing threads rather than processing tasks.
Additionally, contention for shared CPU resources (like cache or memory bandwidth) can occur if
too many threads are competing simultaneously, potentially leading to performance degradation.
Thus, while multithreading can boost CPU utilization when managed properly, unoptimized use
can strain CPU resources and reduce overall efficiency.
 Properly cite all your references (i.e., books, articles, dissertations, websites, etc.). (5
points)

Note: This assessment is 60 points in total.

Grading Rubric for Essay:


Criteria Performance Indicator Points
Content Correct ideas, concepts, and/or examples were included. 3
Organization The presentation of ideas was generally organized. 2
TOTAL 5
Note: DO NOT COPY AND PASTE. All students who copy and paste their work from any website or their classmates will automatically receive a failing mark for this assessment task.
03 Practice Exercise 1 *Property of STI
Page 1 of 1

You might also like