Operating System Assignment 3

You might also like

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

Operating System

Assignment 3

Submitted to:

Prof. Farhan

Submitted By:

Muhammad Arslan Wajid

0080

ADCS 3B

Arslan Wajid
[COMPANY NAME]
OPERATING SYSTEM
ASSIGNMENT 3
CONTENTS

MULTITHREADING MODELS....................................................................................................1

One to One Model.......................................................................................................................2

Many to One Model.....................................................................................................................2

Many to Many Model..................................................................................................................2

THREATS ISSUE...........................................................................................................................2

Types of Thread...........................................................................................................................2

Multithreading Issues...................................................................................................................3

Thread Cancellation.....................................................................................................................3

Signal Handling...........................................................................................................................3

Security Issues.............................................................................................................................3

Critical Section Problem..................................................................................................................4

Solution to Critical Section Problem...........................................................................................4

Mutual Exclusion.....................................................................................................................4

Progress....................................................................................................................................4

Synchronization Hardware..............................................................................................................4

ATOMIC TRANSACTION............................................................................................................5

1
MULTITHREADING MODELS

Multithreading allows the execution of multiple parts of a program at the same time. These parts
are known as threads and are lightweight processes available within the process. Therefore,
multithreading leads to maximum utilization of the CPU by multitasking.
The main models for multithreading are one to one model, many to one model and many to many
models. Details about these are given as follows:

ONE TO ONE MODEL

The one to one model maps each of the user threads to a kernel thread. This means that many
threads can run in parallel on multiprocessors and other threads can run when one thread makes a
blocking system call.
A disadvantage of the one to one model is that the creation of a user thread requires a
corresponding kernel thread. Since a lot of kernel threads burden the system, there is restriction
on the number of threads in the system.

MANY TO ONE MODEL

The many to one model maps many of the user threads to a single kernel thread. This model is
quite efficient as the user space manages the thread management.
A disadvantage of the many to one model is that a thread blocking system call blocks the entire
process. Also, multiple threads cannot run in parallel as only one thread can access the kernel at
a time.

MANY TO MANY MODEL

The many to many model maps many of the user threads to a equal number or lesser kernel
threads. The number of kernel threads depends on the application or machine.
The many to many does not have the disadvantages of the one to one model or the many to one
model. There can be as many user threads as required and their corresponding kernel threads can
run in parallel on a multiprocessor.

2
THREATS ISSUE
Thread is an execution unit which consists of its own program counter, a stack, and a set of
registers. Threads are also known as Lightweight processes. Threads are popular way to improve
application through parallelism. The CPU switches rapidly back and forth among the threads
giving illusion that the threads are running in parallel.

TYPES OF THREAD

There are two types of threads:

1. User Threads
2. Kernel Threads

User threads, are above the kernel and without kernel support. These are the threads that
application programmers use in their programs.

Kernel 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.

MULTITHREADING ISSUES

Below we have mentioned a few issues related to multithreading. Well, it's an old saying, all
good things, come at a price.

THREAD CANCELLATION

Thread cancellation means terminating a thread before it has finished working. There can be two
approaches for this, one is Asynchronous cancellation, which terminates the target thread
immediately. The other is Deferred cancellation allows the target thread to periodically check if
it should be cancelled.

SIGNAL HANDLING

3
Signals are used in UNIX systems to notify a process that a particular event has occurred. Now
in when a Multithreaded process receives a signal, to which thread it must be delivered? It can be
delivered to all, or a single thread.

fork() System Call

fork() is a system call executed in the kernel through which a process creates a copy of itself.
Now the problem in Multithreaded process is, if one thread forks, will the entire process be
copied or not?

SECURITY ISSUES

Yes, there can be security issues because of extensive sharing of resources between multiple
threads.

There are many other issues that you might face in a multithreaded process, but there are
appropriate solutions available for them. Pointing out some issues here was just to study both
sides of the coin.

CRITICAL SECTION PROBLEM


A Critical Section is a code segment that accesses shared variables and has to be executed as an
atomic action. It means that in a group of cooperating processes, at a given point of time, only
one process must be executing its critical section. If any other process also wants to execute its
critical section, it must wait until the first one finishes.

SOLUTION TO CRITICAL SECTION PROBLEM

A solution to the critical section problem must satisfy the following three conditions:

MUTUAL EXCLUSION

Out of a group of cooperating processes, only one process can be in its critical section at a given
point of time.

PROGRESS

4
If no process is in its critical section, and if one or more threads want to execute their critical
section then any one of these threads must be allowed to get into its critical section.

SYNCHRONIZATION HARDWARE
Many systems provide hardware support for critical section code. The critical section problem
could be solved easily in a single-processor environment if we could disallow interrupts to occur
while a shared variable or resource is being modified.

In this manner, we could be sure that the current sequence of instructions would be allowed to
execute in order without pre-emption. Unfortunately, this solution is not feasible in a
multiprocessor environment.

Disabling interrupt on a multiprocessor environment can be time consuming as the message is


passed to all the processors. This message transmission lag, delays entry of threads into critical
section and the system efficiency decreases.

ATOMIC TRANSACTION

An atomic transaction is an indivisible series of database operations such that either all occur,


or nothing occurs. A guarantee of atomicity prevents updates to the database occurring only
partially, which can cause greater problems than rejecting the whole series outright. As a
consequence, the transaction cannot be observed to be in progress by another database client. At
one moment in time, it has not yet happened, and at the next it has already occurred in whole (or
nothing happened if the transaction was cancelled in progress).

An example of an atomic transaction is a monetary transfer from bank account A to account B. It


consists of two operations, withdrawing the money from account A and saving it to account B.
Performing these operations in an atomic transaction ensures that the database remains in
a consistent state, that is, money is neither lost nor created if either of those two operations fail

5
6

You might also like