Chapter 6 - Concurrent Processes Ivy Tech State College Northwest Region 01 CIS106 Microcomputer...

31
Chapter 6 - Chapter 6 - Concurrent Processes Concurrent Processes Ivy Tech State College Northwest Region 01 CIS106 Microcomputer Operating Syste Gina Rue CIS Faculty

Transcript of Chapter 6 - Concurrent Processes Ivy Tech State College Northwest Region 01 CIS106 Microcomputer...

Chapter 6 - Chapter 6 - Concurrent ProcessesConcurrent Processes

Ivy Tech State College Northwest Region 01

CIS106 Microcomputer Operating Systems

Gina RueCIS Faculty

See Illustration p.125 2

Introduction - Introduction - Concurrent ProcessesConcurrent Processes

• Multiprocessing systems have more Multiprocessing systems have more than one CPUthan one CPU– problems that occur in single processor problems that occur in single processor

systems apply to multi-processes in systems apply to multi-processes in generalgeneral• single processor with 2 or more processessingle processor with 2 or more processes

• more than one processor with more than one processor with multiprocessesmultiprocesses

3

What Is Parallel What Is Parallel Processing?Processing?

– Parallel Processing, also called multiprocessing, Parallel Processing, also called multiprocessing, where two or more processors operate in unisonwhere two or more processors operate in unison

– Two or more CPUs are executing instructions Two or more CPUs are executing instructions simultaneouslysimultaneously

– Each CPU can have a process in the RUNNING Each CPU can have a process in the RUNNING state at the same timestate at the same time

– Process Manager has to coordinate the activity Process Manager has to coordinate the activity of each processor, as well as synchronize the of each processor, as well as synchronize the interaction among the CPUsinteraction among the CPUs

4

What Is Parallel What Is Parallel Processing?Processing?

– Synchronization is the key to the system’s Synchronization is the key to the system’s success because many things can go wrong success because many things can go wrong in a multiprocessing systemin a multiprocessing system

– The system won’t work unless every The system won’t work unless every processor communicates & cooperates with processor communicates & cooperates with every other processorevery other processor

– Since mid-1980s, costs of CPU hardware Since mid-1980s, costs of CPU hardware declined, has increased multiprocessors declined, has increased multiprocessors used in business environment todayused in business environment today

5

What Is Parallel What Is Parallel Processing?Processing?

– Two major forces behind Two major forces behind multiprocessing developmentmultiprocessing development• enhance throughputenhance throughput

• increase computing powerincrease computing power

– Two primary benefitsTwo primary benefits• increased reliabilityincreased reliability

• faster processingfaster processing

6

Typical Multiprocessing Typical Multiprocessing ConfigurationsConfigurations

Much depends on how multiple Much depends on how multiple processors are configured. Three processors are configured. Three typical configurations are:typical configurations are:

– master/slavemaster/slave

– loosely coupledloosely coupled

– symmetricsymmetric

See Fig. 6.1 p.128 7

Master/Slave Master/Slave ConfigurationConfiguration

• Single-processor (master) with additional (slave) Single-processor (master) with additional (slave) processorsprocessors

– master processor manages entire systemmaster processor manages entire system

– well suited for front-end users (interactive) & back-well suited for front-end users (interactive) & back-end users (batch) end users (batch)

– advantage is simplicityadvantage is simplicity

– disadvantagesdisadvantages• reliability is no higher than single processorreliability is no higher than single processor

• can lead to poor use of resourcescan lead to poor use of resources

• increase # of interrupts, slave/masterincrease # of interrupts, slave/master

See Fig. 6.2 p.128 8

Loosely Coupled Loosely Coupled ConfigurationConfiguration

• Several complete computer systems, each Several complete computer systems, each with its own memory, I/O devices, CPU, & OSwith its own memory, I/O devices, CPU, & OS– each processor controls its own resourceseach processor controls its own resources

– each processor can communicate & cooperate with the each processor can communicate & cooperate with the others others

– job scheduling for new jobs may be assigned to job scheduling for new jobs may be assigned to processor with lightest load or best combination of processor with lightest load or best combination of output devicesoutput devices

– if one processor fails, others can continue to work if one processor fails, others can continue to work independently, difficult to detect failed processorindependently, difficult to detect failed processor

See Fig. 6.3 p.129 9

Symmetric ConfigurationSymmetric Configuration• Processor scheduling is decentralizedProcessor scheduling is decentralized

• Best implemented if the processors are all Best implemented if the processors are all of the same typeof the same type

– four advantages over loosely coupled:four advantages over loosely coupled:•more reliablemore reliable

•uses resources effectivelyuses resources effectively

•balances load wellbalances load well

•degraded gracefully in the event of system failuredegraded gracefully in the event of system failure

10

Process Synchronization Process Synchronization SoftwareSoftware

• Success hinges on the capability of the OS Success hinges on the capability of the OS to make resources unavailable to other to make resources unavailable to other processes while it’s being used by one of processes while it’s being used by one of themthem

• Used resources must be locked away from Used resources must be locked away from other processes until it is released - other processes until it is released - critical critical regionregion allow a process to finish allow a process to finish

• A mistake could leave a job waiting A mistake could leave a job waiting indefinitelyindefinitely

11

Test-And-SetTest-And-Set

• singlesingle indivisible machine instruction indivisible machine instruction known as “TS”known as “TS”

• introduced by IBM for System introduced by IBM for System 360/370 computers 360/370 computers

• In a machine cycle it tests if the key In a machine cycle it tests if the key is available/unavailableis available/unavailable

• single bit in a storage location that can single bit in a storage location that can contain a zero (free) or one (busy)contain a zero (free) or one (busy)

12

Test-And-SetTest-And-Set

• Simple to implement & works well for a Simple to implement & works well for a small # of processessmall # of processes

• two drawbacks:two drawbacks:•starvationstarvation can occur when many can occur when many

processes are waiting to enter critical processes are waiting to enter critical regionregion

•busy waitingbusy waiting-the waiting processes -the waiting processes remain in unproductive, resource-remain in unproductive, resource-consuming wait loopsconsuming wait loops

13

WAIT and SIGNALWAIT and SIGNAL

• Modification of “TS” designed to remove Modification of “TS” designed to remove busy waitingbusy waiting

• Two operations are mutually exclusive:Two operations are mutually exclusive:•WAIT activated when the process WAIT activated when the process

encounters a busy condition codeencounters a busy condition code

•SIGNAL activated when the process exits SIGNAL activated when the process exits the critical region, condition code is set to the critical region, condition code is set to “free”“free”

See Table 6.1 p.133 14

SemaphoresSemaphores

• A nonnegative integer variable that’s A nonnegative integer variable that’s used as a flagused as a flag

• signals if and when a resource is free signals if and when a resource is free & can be used to process& can be used to process•Dijkstra (1965) introduced two Dijkstra (1965) introduced two

operations to overcome process operations to overcome process synchronization problemssynchronization problems• P - proberen (to test)P - proberen (to test)• V - verhogen (to increment)V - verhogen (to increment)

15

SemaphoresSemaphores

• P & V are executed by the OS in P & V are executed by the OS in response called issued by any one response called issued by any one process naming a semaphore as process naming a semaphore as parameterparameter

• Traditional name for semaphore is Traditional name for semaphore is mutex - Mutual Exclusionmutex - Mutual Exclusion•necessary to avoid two operations necessary to avoid two operations

attempt to execute at the same timeattempt to execute at the same time

16

SemaphoresSemaphores

• Sequential computations, mutex is Sequential computations, mutex is achieved automatically because each achieved automatically because each operation is handled in order, one at operation is handled in order, one at a timea time

• Parallel computations, order of Parallel computations, order of execution can change, so mutex execution can change, so mutex must be explicitly stated & must be explicitly stated & maintainedmaintained

17

Process CooperationProcess Cooperation

Several processes work together to Several processes work together to complete a common task, two complete a common task, two examples:examples:•producers and consumersproducers and consumers

•readers and writers readers and writers

Each requires both mutual exclusion Each requires both mutual exclusion and synchronization, they are and synchronization, they are implemented by using semaphoresimplemented by using semaphores

See Fig. 6.5 p.135 18

Producers and ConsumersProducers and ConsumersClassic problem:Classic problem:

• One process produces data that another One process produces data that another process consumes laterprocess consumes later

• It can also be expanded to several pairs It can also be expanded to several pairs of producers and consumersof producers and consumers

• Can be extended to buffers that hold Can be extended to buffers that hold records or data where process-to-process records or data where process-to-process communication is requiredcommunication is required

19

Readers and WritersReaders and WritersClassic problem:Classic problem:

• Two processes need to access a shared resource Two processes need to access a shared resource such as a file or databasesuch as a file or database

• Combination priority policy used to prevent Combination priority policy used to prevent starvationstarvation

• Readers must call two procedures:Readers must call two procedures:– checks whether the resources can be immediately checks whether the resources can be immediately

granted for readinggranted for reading

– checks to see if there are any writers waitingchecks to see if there are any writers waiting

20

Concurrent ProgrammingConcurrent Programming

Multiprocessing can also refer to Multiprocessing can also refer to one job using several processors one job using several processors to execute sets of instructions in to execute sets of instructions in parallelparallel

– requires a programming languagerequires a programming language

– requires a system to this type requires a system to this type

See Table 6.2 p.138 21

Applications of Concurrent Applications of Concurrent ProgrammingProgramming

Monoprogramming languagesMonoprogramming languages• instructions are executed one at a instructions are executed one at a

timetime

•sufficient for most computational sufficient for most computational purposespurposes– easy to implementeasy to implement– fast enough for most usersfast enough for most users

22

Applications of Concurrent Applications of Concurrent ProgrammingProgramming

By using a language that allows By using a language that allows concurrent processing, arithmetic concurrent processing, arithmetic expressions can be processed expressions can be processed differently differently

•COBEGINCOBEGIN

•COENDCOEND– indicate to a compiler which instructions indicate to a compiler which instructions

can be processed concurrentlycan be processed concurrently

See Table 6.3 p.138 23

Applications of Concurrent Applications of Concurrent ProgrammingProgramming

When operations are performed at the same When operations are performed at the same time, we increase computation speed, but time, we increase computation speed, but also create complexity of the program also create complexity of the program language & hardwarelanguage & hardware

•explicit parallelismexplicit parallelism– detects which instructions can be executed in detects which instructions can be executed in

parallelparallel

• implicit parallelismimplicit parallelism– automatic detection by the compiler of automatic detection by the compiler of

instructions that can be performed in parallelinstructions that can be performed in parallel

24

ADA - Agusta Ada ByronADA - Agusta Ada Byron• U.S. Department of Defense early 1970sU.S. Department of Defense early 1970s

• Designed original language for embedded Designed original language for embedded computer systemscomputer systems

• Ada - high-level programming language made Ada - high-level programming language made available to public in 1980available to public in 1980– modules support “information hiding”modules support “information hiding”

– implement concurrent programmingimplement concurrent programming

– design made it easy to verify correctness of a design made it easy to verify correctness of a programprogram

25

Ada - Modular Ada - Modular ProgrammingProgramming

An Ada program would contain one or more An Ada program would contain one or more program units that could be compiled program units that could be compiled separately and were composed of:separately and were composed of:– a specification part, which has all the a specification part, which has all the

information that must be visible to other units information that must be visible to other units (the argument list)(the argument list)

– a body part, made up of implementation details a body part, made up of implementation details that don’t need to be visible to other unitsthat don’t need to be visible to other units

26

Ada - Modular Ada - Modular ProgrammingProgramming

Program units can fall into any one of three Program units can fall into any one of three types:types:– subprograms which are executable algorithmssubprograms which are executable algorithms

– packages which are collections of entities, packages which are collections of entities, (procedures or functions)(procedures or functions)

– tasks which are concurrent computationstasks which are concurrent computations• is the heart of the language’s parallel processing is the heart of the language’s parallel processing

abilityability

• key is synchronization of the taskskey is synchronization of the tasks

27

Ada - The wave of the Ada - The wave of the future?future?

Landmark language:Landmark language:– researchers find it helpful because of parallel researchers find it helpful because of parallel

processing powerprocessing power

– modular design is appealing to application modular design is appealing to application programmers and systems analystsprogrammers and systems analysts

– tasking capabilities appeal to designers of database tasking capabilities appeal to designers of database systems & other applications that require parallel systems & other applications that require parallel processingprocessing

– some universities offer Ada courses majoring in some universities offer Ada courses majoring in computer systemscomputer systems

28

SummarySummary

• Multiprocessing systems have two or more CPUs Multiprocessing systems have two or more CPUs that must be synchronized by the Process that must be synchronized by the Process ManagerManager

• Each processor must communicate with the otherEach processor must communicate with the other

• Multiprocessor configurationsMultiprocessor configurations– master/slavemaster/slave

– loosely coupledloosely coupled

– symmetricsymmetric

29

SummarySummary

• Multiprocessing also occurs in single Multiprocessing also occurs in single processor systems between interacting processor systems between interacting processes that obtain control of the processes that obtain control of the CPU at different timesCPU at different times

• Success depends on the ability of the Success depends on the ability of the system to synchronize the processors system to synchronize the processors or processes & the system’s other or processes & the system’s other resourcesresources

30

SummarySummary

• Mutual exclusion helps keep the Mutual exclusion helps keep the processes having allocated resources processes having allocated resources from becoming deadlockedfrom becoming deadlocked

– test-and-settest-and-set

– WAIT and SIGNALWAIT and SIGNAL

– semaphores (P - proberen,V – verhogen, semaphores (P - proberen,V – verhogen, and mutex)and mutex)

31

SummarySummary

• Hardware & Software are used to Hardware & Software are used to synchronize processessynchronize processes

• Synchronization problemsSynchronization problems– missed waiting customersmissed waiting customers

– synchronization of producers & synchronization of producers & consumersconsumers

– mutual exclusion of readers & writersmutual exclusion of readers & writers