Instructions
• The Forum
Lively and respectful discussions are encouraged
Daily readings
Weekly discussion questions
• Quizzes and Worksheets
On eLearning platform
• Tests (Please note that your account must be up-to-date for you to take part in the
test)
Multiple choice questions
Shorts answer questions
Long answer questions
• All assessments will be graded and contribute to your continuous assessment marks
Enquiries and questions
Lecturer– Mr P. Musindo
Head of Department – Mr C. Kasumba
23/03/2021 Operating Systems
Topic
Threading & parallel
processing.
Operating Systems 2
Lesson Overview
This lesson will focus on the concept of threads in a computer system. It will
look at the relationship between a thread and a process, together with
advantages and disadvantages of each. The lesson will also focus on the
types of threads available in a computing environment. Another concept
covered in this lesson is on parallel processing.
Operating Systems 3
Lesson Objective(s)
At the end of the lesson, students will be able to:
Define a thread
Differentiate between a thread and a process
Explore types of threads
Explain the concept of parallel processing
Operating Systems 4
Introduction
A thread in computer science is short for a thread of execution. Threads are a
way for a program to split itself into two or more simultaneously running tasks.
Threads and processes differ from one operating system to another, but in
general, the way that a thread is created and shares its resources is different
from the way a process does.
Multiple threads can be executed in parallel on many computer systems. This
multithreading generally occurs by time slicing, wherein a single processor
switches between different threads, in which case the processing is not
literally simultaneous, for the single processor is only really doing one thing at
a time. This switching can happen so fast as to give the illusion of
simultaneity to an end user.
The idea of threading is to achieve parallelism by dividing a process into
multiple threads. For example, in a browser, multiple tabs can be different
threads. MS Word uses multiple threads: one thread to format the text,
another thread to process inputs, etc
Operating Systems 5
Single thread vs multitheread
Single threaded process and multithreaded process
Operating Systems 6
Threads compared with processes
Similarities
Like processes threads share CPU and only one thread active (running) at a
time.
Like processes, threads within a process execute sequentially.
Like processes, thread can create children.
And like process, if one thread is blocked, another thread can run.
Differences
Unlike processes, threads are not independent of one another.
Unlike processes, all threads can access every address in the task .
Unlike processes, thread are design to assist one other. Note that
processes might or might not assist one another because processes may
originate from different users.
Operating Systems 7
Examples of threads
For example in a word processor, a background thread may check spelling
and grammar while a foreground thread processes user input ( keystrokes ),
while yet a third thread loads images from the hard drive, and a fourth does
periodic automatic backups of the file being edited.
Another example is a web server - Multiple threads allow for multiple
requests to be satisfied simultaneously, without having to service requests
sequentially or to fork off separate processes for every incoming request.
Operating Systems 8
Benefits of threads
Responsiveness - One thread may provide rapid response while other
threads are blocked or slowed down doing intensive calculations.
Resource sharing - By default threads share common code, data, and
other resources, which allows multiple tasks to be performed
simultaneously in a single address space.
Economy - Creating and managing threads ( and context switches
between them ) is much faster than performing the same tasks for
processes.
Scalability, i.e. Utilization of multiprocessor architectures - A single
threaded process can only run on one CPU, no matter how many may
be available, whereas the execution of a multi-threaded application may
be split amongst available processors. ( Note that single threaded
processes can still benefit from multi-processor architectures when
there are multiple processes contending for the CPU, i.e. when the load
average is above some certain threshold. )
Operating Systems 9
Multicore Programming
chips with multiple cores, or CPUs on a single chip.
Concurrent execution on a single-core system.
Parallel execution on a multicore system
Operating Systems 10
Types of Threads
User - Level Threads
Kernel-Level Threads
Operating Systems 11
User - Level Threads
Are above the kernel and without kernel support. These are the threads that
application programmers use in their programs.
User-level threads are small and much faster than kernel level threads. They are
represented by a program counter(PC), stack, registers and a small process control
block.
Advantages of User-Level Threads
User-level threads are easier and faster to create than kernel-level threads. They can
also be more easily managed.
User-level threads can be run on any operating system.
There are no kernel mode privileges required for thread switching in user-level
threads.
Disadvantages of User-Level Threads
Multithreaded applications in user-level threads cannot use multiprocessing to their
advantage.
The entire process is blocked if one user-level thread performs blocking operation.
Operating Systems 12
Kernel-Level Threads
Are supported within the kernel of the OS itself. All modern OSs support kernel-level
threads, allowing the kernel to perform multiple simultaneous tasks and/or to service
multiple kernel system calls simultaneously.
Because of this, kernel-level threads are slower than user-level threads.
Advantages of Kernel-Level Threads
Multiple threads of the same process can be scheduled on different processors in
kernel-level threads.
The kernel routines can also be multithreaded.
If a kernel-level thread is blocked, another thread of the same process can be
scheduled by the kernel.
Disadvantages of Kernel-Level Threads
A mode switch to kernel mode is required to transfer control from one thread to
another in a process.
Kernel-level threads are slower to create as well as manage as compared to user-
level threads.
Operating Systems 13
Parallel Processing
Parallel Processing Systems are designed to speed up the execution of programs
by dividing the program into multiple fragments and processing these fragments
simultaneously. Such systems are multiprocessor systems also known as tightly
coupled systems. Parallel systems deal with the simultaneous use of
multiple computer resources that can include a single computer with multiple
processors, a number of computers connected by a network to form a parallel
processing cluster or a combination of both.
A parallel processing system can carry out simultaneous data-processing to achieve
faster execution time.
Operating Systems 14
Parallel Processing cont…
All the processors in the parallel processing environment should run on the same
operating system.
All processors here are tightly coupled and are packed in one casing.
All the processors in the system share the common secondary storage like the hard
disk.
Operating Systems 15
Summary
A thread entails a program splitting into two or more running tasks.
Multithreading refers to the activity where a single processor switches between
different threads
Single threaded process is when a single command is executed per given time while
multithreaded processes allow the execution of various instructions at the same time
while sharing resources.
Threads use very little resources of an operating system in which they are working as
compared to processes.
Threads are divided into user-level and kernel-level threads.
Parallel Processing Systems entails dividing the program into multiple fragments and
processing these fragments simultaneously.
Operating Systems 16
Review / discussion questions
1. Differentiate between the following;
▪ user-level threads
▪ Kernel-level threads
2. Compare the single threaded process and a multithreaded process
3. Outline any 2 differences between a process and a thread
4. Explain any 3 advantages a thread has over a process
Operating Systems 17
Resources
https://www.youtube.com/watch?v=exbKr6fnoUw
https://www.youtube.com/watch?v=q7sgzDH1cR8
Stallings, W (2018).Operating Systems: Internals and Design Principles (9th
Edition)
Study Guide
Operating Systems 18
The End
Thank you
Operating Systems 19