Module 2 - Processes and Threads
Module 2 - Processes and Threads
26/12/2021
College of Computing and Informatics
OPERATING SYSTEMS
Operating Systems
Module 2
Chapter 3: Processes
Chapter 4: Threads & Concurrency
CONTENTS
Process Concept
Process Scheduling
Operations on Processes
Inter-Process Communication
Multicore Programming
Multithreading Models
Threading Issues
WEEKLY LEARNING OUTCOMES
Identify the separate components of a process and illustrate how they are
represented and scheduled in an operating system.
A process is independent if it does not share data with any other processes
executing in the system.
Shared memory
Message passing
INTERPROCESS COMMUNICATION
(a) Shared memory. (b) Message passing.
IPC IN SHARED-MEMORY SYSTEMS
An area of memory shared among the processes that wish to communicate
The communication is under the control of the users processes not the operating
system.
Major issues is to provide mechanism that will allow the user processes to
synchronize their actions when they access shared memory.
IPC IN SHARED-MEMORY SYSTEMS
Bounded-Buffer – Shared-Memory Solution
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
CONSUMER PROCESS – SHARED MEMORY
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
Types of parallelism
Data parallelism – distributes subsets of the same data across
multiple cores, same operation on each
Task parallelism – distributing threads across cores, each thread
performing unique operation
DATA AND TASK PARALLELISM
USER THREADS AND KERNEL THREADS
User threads - management done by user-level threads library
Three primary thread libraries:
POSIX Pthreads
Windows threads
Java threads
Kernel threads - Supported by the Kernel
Examples – virtually all general -purpose operating systems, including:
Windows
Linux
Mac OS X
iOS
Android
USER THREADS AND KERNEL THREADS
MULTITHREADING MODELS
Many-to-One
One-to-One
Many-to-Many
MANY TO ONE MODEL
Many user-level threads mapped to single kernel thread
One thread blocking causes all to block
Multiple threads may not run in parallel on muticore system because only one may
be in kernel at a time
Few systems currently use this model
Examples:
Solaris Green Threads
GNU Portable Threads
ONE TO ONE MODEL
Each user-level thread maps to kernel thread
Creating a user-level thread creates a kernel thread
More concurrency than many-to-one
Number of threads per process sometimes restricted due to overhead
Examples
Windows
Linux
MANY TO MANY MODEL
Allows many user level threads to be mapped to many kernel threads
Allows the operating system to create a sufficient number of kernel threads
Windows with the ThreadFiber package
Otherwise not very common
THREADING ISSUES
Semantics of fork() and exec() system calls
Signal handling
Asynchronous or deferred
Thread-local storage
Scheduler Activations
Main Reference
Chapter 3: Processes
Chapter 4: Threads & Concurrency
(Operating System Concepts by Silberschatz, Abraham, et al. 10th ed.,
ISBN: 978-1-119-32091-3, 2018)
Additional References
Chapter 2.1
Chapter 2.2
(Modern Operating Systems by Andrew S. Tanenbaum and Herbert Bos. 4th
ed., ISBN-10: 0-13-359162-X, ISBN-13: 978-0-13-359162-0, 2015)
sentation is mainly dependent on the textbook: Operating System Concepts by Silberschatz, Abrah
Thank You