Docsity

Lecture 9: Concurrent Processes in Operating Systems, Study notes of Operating Systems

Partial preview of the text

Download Lecture 9: Concurrent Processes in Operating Systems and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems

Lecture #9: Concurrent Processes

Written by David Goodwin

based on the lecture series of Dr. Dayou Li

and the book Understanding Operating Systems 4

th

ed.

by I.M.Flynn and A.McIver McHoes (2006)

Department of Computer Science and Technology,

University of Bedfordshire.

Operating Systems, 2013

th

April 2013

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations

Programming

Threads

Operating Systems

Outline

1 Introduction

2 Configurations

3 Programming

4 Threads

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction 4

Configurations

Programming

Threads

Operating Systems

What is parallel processing?

ˆ Parallel processing (also called multiprocessing)

ˆ situation in which two or more procesors operate in unison

ˆ i.e. two or more CPUs are executing instructions

simultaneously

ˆ each CPU can have a RUNNING process at the same time

ˆ Process manager must coordinate each processor

ˆ Process manager must synchronise the interaction among

CPUs

ˆ enhance throughput and increase computing power

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction 5

Configurations

Programming

Threads

Operating Systems

What is parallel processing?

ˆ Example: Information Retrieval System

ˆ (^) Processor 1

ˆ accepts a query ˆ checks for errors ˆ (^) passes request to Processor 2

ˆ Processor 2

ˆ (^) searches database for required information

ˆ Processor 3

ˆ (^) retrieves data from database (if kept off-line in secondary

storage) ˆ (^) data placed where Processor 2 can get it

ˆ Processor 2

ˆ (^) passes information to Processor 4

ˆ Processor 4

ˆ (^) routes the response back to the originator of the request

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations 7

Programming

Threads

Operating Systems

Configurations

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations 8

Programming

Threads

Operating Systems

Master/Slave configuration

ˆ Master/Slave configuration is asymmetric

ˆ (^) Essentially a single processor with additional “slaves”

ˆ Master processor responsible for managing entire system

ˆ maintains status of processes, storage management, schedules

work for slave processors, executes all control programs.

ˆ (^) suited for environments with front-end interactive users, and

back-end batch job mode

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations 10

Programming

Threads

Operating Systems

Loosely Coupled configuration

ˆ Loosely Coupled system features several complete computing

systems

ˆ each has its own memory, IO devices, CPU, and OS

ˆ each processor controls its own resources ˆ (^) each processor can communicate and cooperate with others

ˆ job assigned to one processor, and will remain there until

finished ˆ job scheduling based on several requiremenyts and policies

(new jobs may be assigned to the processor with lightest load)

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations 11

Programming

Threads

Operating Systems

Loosely Coupled configuration

ˆ Advantage:

ˆ (^) Isn’t prone to catastrophic system failures (when a processor

fails, others can continue work independently)

ˆ Disadvantage:

ˆ Difficult to detect when a processor has failed

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations 13

Programming

Threads

Operating Systems

Symmetric configuration

ˆ Advantage:

ˆ Reliable

ˆ Uses resources effectively

ˆ Balance loads well

ˆ Can degrade gracefully in the event of a failure

ˆ Disadvantage:

ˆ (^) Processors must be well synchronised to avoid problems of

races and deadlocks

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations

Programming 14

Threads

Operating Systems

Programming

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations

Programming 16

Threads

Operating Systems

Concurrent Programming Applications

ˆ Example:

ˆ (^) A = 3 ∗ B ∗ C + 4/(D + E) ∗ ∗(F − G)

step Operation Result

1 (F − G) Store difference in T 1

2 (D + E) Store sum in T 2

3 (T 1 ) ∗ ∗(T 2 ) Store power in T 1

4 4 /(T 1 ) Store quotient in T 2

5 3 ∗ B Store product in T 1

6 (T 1 ) ∗ C Store product in T 1

7 (T 1 ) + (T 2 ) Store sum in A

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations

Programming 17

Threads

Operating Systems

Concurrent Programming Applications

ˆ Arithmetic expressions can be processed differently if we use a

language that allows concurrent processing

ˆ (^) Define COBEGIN and COEND to indicate to the compiler

which instructions can be processed concurrently

ˆ COBEGIN

T 1 = 3 ∗ B

T 2 = D + E

T 3 = F − G

COEND

ˆ COBEGIN

T 4 = T 1 ∗ C

T 5 = T 2 ∗ ∗T 3

COEND

ˆ (^) A = T 4 + 4/T 5

step proc. Operation Result

1 1 3 ∗ B Store difference in T 1

2 (D + E) Store sum in T 2

3 (F − G) Store difference in T 3

2 1 (T 1 ) ∗ C Store product in T 4

2 (T 2 ) ∗ ∗(T 3 ) Store power in T 5

3 1 4 /(T 5 ) Store quotient in T 1

4 1 (T 4 ) + (T 1 ) Store sum in A

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations

Programming 19

Threads

Operating Systems

Case 1: Array Operations

ˆ To perform an array operation within a loop in three steps,

the instruction might say:

ˆ (^) for(j=1;j<=3;j++)

a(j)=b(j)+c(j);

ˆ If we use three processors, the instruction can be performed

in a single step:

ˆ (^) processor#1 performs: a(1)=b(1)+c(1)

processor#2 performs: a(2)=b(2)+c(2)

processor#3 performs: a(3)=b(3)+c(3)

Lecture # Concurrent Processes David Goodwin University of Bedfordshire

Introduction

Configurations

Programming 20

Threads

Operating Systems

Case 2: Matrix Multiplication

ˆ To perform C = A ∗ B where A and B represent two

matricies:

ˆ (^) A =

1 2 3

4 5 6

7 8 9

, B =

1 2 3

4 5 6

7 8 9

ˆ Several elements of a row of A are multiplied by the

corresponding elements of the column in B.

ˆ Serially, the answer can be computed in 45 steps ( 5 × 9 )

ˆ With three processors the answer takes only 27 steps,

multiplying in parallel ( 3 × 9 )