0% found this document useful (0 votes)
2 views

COSC 823 Lecture Slide -4

The document discusses advanced operating systems with a focus on concurrency, multithreading, and multiprocessing architectures. It defines key concepts such as race conditions, mutual exclusion, and the differences between symmetric and asymmetric multiprocessing. The document also highlights the importance of concurrency in OS design and provides examples to illustrate race conditions in programming.

Uploaded by

badmusyahyah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

COSC 823 Lecture Slide -4

The document discusses advanced operating systems with a focus on concurrency, multithreading, and multiprocessing architectures. It defines key concepts such as race conditions, mutual exclusion, and the differences between symmetric and asymmetric multiprocessing. The document also highlights the importance of concurrency in OS design and provides examples to illustrate race conditions in programming.

Uploaded by

badmusyahyah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

ADVANCED OPERATING

SYSTEMS– COSC 823


(Module -4)

By
Dr. M.O. Eze
Department of Computer Science,
Babcock University, Ilisan-Remo, Ogun State, Nigeria
CONCURRENCY IN OS

CONTENTS

SMP and ASMP


Threading Concept Race Condition Etc.
Architectures
MULTITHREADING
DEFINITION:

Multithreading refers to the ability of an OS to

support multiple, concurrent paths of execution

within a single process. The traditional

approach of a single thread of execution per

process, in which the concept of a thread is not

recognized, is referred as a single-threaded

approach.
THREAD OPTIONS
MULTITHREADING

LHS Partition:
The two arrangements in the LHS Partition represent

single-threaded approaches.

Example:

MS Dos  an OS that supports a single user process and a

single thread.

Old Versions of UNIX  Support multiple user processes

but only one thread per process.


MULTITHREADING
RHS Partition:
The two arrangements in the RHS Partition depicts

multithreaded approaches.

Examples:

Java Run-time Environment Supports one process with

multiple threads.

Modern OSs like Windows, Solaris & new versions of UNIX

 Support multiple processes, each supporting multiple

threads.
OS CONCURRENCY

A FUNDAMENTAL ISSUE:
Concurrency is a fundamental issue to OS Design. Concurrency

encompasses serious design issues, including:

- Process Communication

- Resource Sharing for processes competing for resources

(such as memory, files, I/O access, etc)

- Synchronization of the activities of the processes

- CPU Scheduling for use of CPU by processes

- Etc.
OS CONCURRENCY

BASIC REQUIREMENT:

The basic requirement for concurrency is

the ability to enforce mutual exclusion.

This is the ability of the system to exclude

all other processes by granting a


activity, while
particular process the exclusive right.
OS CONCURRENCY
Terms KEYDefinition
TERMS:
Atomic A sequence of one or more statements, representing
Operation operations whose intermediate states can neither be
seen nor interrupted by others.

Critical This is a section of code within a process that requires


Section: access to shared resources and that must not be
executed while another process is in a corresponding
section of code.

Deadlock This is a situation where two or more processes are


unable to proceed because each is waiting for one of the
others to relinquish a resource which it personally needs.

Livelock This is a situation where a number of processes keep


changing their states in response to changes in the
other process(es) without performing any useful work.
OS CONCURRENCY
Terms KEYDefinition
TERMS:
Mutual This is a requirement that when one process is in a
Exclusion critical section that accesses shared resources, no other
process may be able to accesses those particular shared
resources.

Race This refers to a situation where multiple processes or


Condition threads read and write a shared data item, and the final
result depends on the order in which the execution
occurred.
Starvation This is a situation where the scheduler overlooks a
runnable process indefinitely, such that even when it’s a
position to proceed, it is never selected or given a
chance to run.
Multiprocessing Architectures
The two common multi-processing

architectures are:

1. SMP (Symmetric

Multiprocessors)

2. ASMP (Asymmetric

Multiprocessors)
ASMP
In asymmetric multiprocessing (ASMP), the OS :

a. Sets aside one or more Exclusive Processors.

b. The remaining ones are the Non-Exclusive

Processors.

The exclusive processors are dedicated for OS use only,

while the non-exclusive processors are used for running

the user programs.


ASMP
Attributes of ASMP Model

1. In many cases, the exclusive processor could fall behind the

other processors running user applications.

2. The implication is that the applications often have to wait

while the OS catches up.

3. Such a drag leads to reduction in the overall throughput of

the system.

4. In the ASMP model, if an exclusive processor fails, the whole

system could go down.


SMP
The Symmetric multiprocessing (SMP)

technology is a newer model, that aims to deal

with the gaps in ASMP. In symmetric

multiprocessing:

1. Each processor can run any type of thread.

Thus, none is exclusively dedicated to the OS.

2. The processors communicate with

themselves through shared memory.


SMP

3. The SMP model provide better load-

balancing and fault tolerance than the

ASMP.

4. A processor failure in the SMP

model does not lead to the failure of

the whole system.


SMP Vs ASMP Complexity

In terms of complexity,

the SMP model is much

more complex than the

ASMP.
Interleaved Execution
Interleaved Execution
Race Condition
A Race Condition is a form of competition

resulting from the interaction of multiple

processes or threads.

The summary or Race Condition is as follows:

1. Multiple Processes or threads read and write

data items.

2. Final result depends on the order in which


Race Condition

Consider the following code segment. It accepts

character inputs through the keyboard, and

displays the outcome on the screen.

void echo( );
{
CharIn=GetChar( );
Cout=CharIn;
PutChar(Cout);
}
Race Condition

In the code segment, inputs come to the

keyboard single keystrokes at a time. These

input characters are first accepted as variable

‘Charin’, then get transferred to a second

variable ‘Cout’ before being displayed through

the invocation of an internal function

‘PutChar’.
Race Condition
Because different users perform character
transmission to screen as often as possible, the
echo module is written and stored for re-use by
different processes.

ILLUSTRATION 1:

Suppose two users processes P1 and P2


attempt to access the echo module. Process P1
keys in ‘A’ first, and then after a while, P2 keys
in ‘B’.
Race Condition
Obviously, it is very possible that ‘B’
which was written last by process P2
may end up overwriting ‘A’, even though
it was written first by process P1. Thus,
while P1 and P2 are struggling to display
their characters, only ‘B’ ends up being
displayed while ‘A’ is lost in transit. This
is especially true if P1 was at an
intermediate stage when P2 stepped in
Race Condition
ILLUSTRATION 2:

Again, suppose two processes P3 and P4 share


common variables x and y. Let the initial values
of these variables be x=1 and y=2. If at some
point in the program execution, P3 executes
x=x+y, while P4 executes y=x+y. Based on the
concept of Race Condition, it can be shown that
though P3 and P4 update different variables,
the final values depend on the order of
execution.
Race Condition
INITIALIZATION: x=1, y=2,

Case 1:

Let P3 execute first: x = x+y  3

THEN P4 executes: y=x+y = 3+2 5

Case 2:

Let P4 execute first: y=x+y  3

THEN P3 executes: x=x+y =1+3 4


Race Condition

OUTCOMES:

Thus, if P3 executes first before P4, the values


of the common variables x and y will be:

x=3 and y=5.

But if P4 executes first before P3, the values of


the common variables x and y will be:

x=4 and y=3.


QUESTION
Student should give other practical examples to illustrate the
concept of Race Conditions.
REFERENCE/RECOMMENDED TEXT

Abraham Silberschatz, Peter Galvin, and Greg


Gagne,
"Operating System Concepts", 9th Ed, Published
by John Wiley & Sons, Inc., NJ USA, 2013

You might also like