28
1 Concurrency Specification

Concurrency Specification

  • Upload
    damisi

  • View
    79

  • Download
    0

Embed Size (px)

DESCRIPTION

Concurrency Specification. Outline. Issues in concurrent systems Programming language support for concurrency Concurrency analysis - A specification based approach Concurrency and other formal methods Deadlock checker Concurrency and architectures. Concurrency. - PowerPoint PPT Presentation

Citation preview

Page 1: Concurrency Specification

1

Concurrency Specification

Page 2: Concurrency Specification

2

Outline

Issues in concurrent systems Programming language support for

concurrency Concurrency analysis - A specification based

approach Concurrency and other formal methods Deadlock checker Concurrency and architectures

Page 3: Concurrency Specification

3

Concurrency

Coexistence Sharing of resources Issues

– Asynchronicity– Non-determinism

Solution– Locks

Results– Deadlock and starvation

Page 4: Concurrency Specification

4

Concurrency in Various Disciplines Databases

– Transaction serializability Operating systems

– Multithreading Electronic circuits

– Flip flops Real life

– Gas station example

Page 5: Concurrency Specification

5

Concurrency in Architecture Implementations

Component 1

Connector

Component 2

MessageQueue

Message Object AA'

.

.create(request);

.

.create(request);

.send(request);

A'

A'A'

A'

A'

handle(request){ send_to_all_upper_components(request);}

handle(request){

process(request);...

handle(request){

process(request);...

create(notification);...

}

handle(request){

process(request);...

create(notification);...

send(notification);}

A'

A'

Page 6: Concurrency Specification

6

PL Support for Concurrency - 1

Fork and join constructs Queue construct and the signal

operation– Concurrent Pascal

The Java synchronized keyword

Page 7: Concurrency Specification

7

PL Support for Concurrency - 2

Communicating sequential processes [CSP]– Producer command : consumer!m– Consumer command : producer?n– Guarded commands

• <guard> —› <command-list>• guard : list of declarations, boolean expressions or an

input command• Alternative guarded command

– [ G1 —› C1 ƀ G2 —› C2 ƀ …. ƀ Gn —› Cn]

Page 8: Concurrency Specification

8

From Specification to Implementation Specification Phase Implementation Phase Easy to verify safety Difficult to verify and liveness safety and liveness State spaces small State spaces and manageable large and unmanageable; testing difficult Cost of correcting Cost of correcting flaws is low flaws is high

Page 9: Concurrency Specification

9

Specification-Based Model - 1

Synchronizer construct– Set of variables defining the state of

shared resources– Set of operations on these variables (with

pre/post conditions)– Set of invariants

• Safety conditions• Liveness conditions

Page 10: Concurrency Specification

10

Specification-Based Model - 2

Process construct– Independent thread of execution– Multiple processes coexist– Control allocation/deallocation of synchronizer controlled resources

Example:– Web server : synchronizer– Web browser : process

Page 11: Concurrency Specification

11

Gas-Station Model

Page 12: Concurrency Specification

12

Gas-Station Model - Program Spec

Page 13: Concurrency Specification

13

Gas Station Model - RSTG

Page 14: Concurrency Specification

14

Gas Station Model - Event Expressions Two customers trying to buy gas concurrently

Page 15: Concurrency Specification

15

Gas Station Model - Reachability Graph Identifies the states that can be reached by executing enabled operations in processes and synchronizers Constructed from event expressions and RSTG

– Nodes represent states of RSTG– Edges represent operations from event expressions

A deadlock occurs if the graph contains terminal nodes

Page 16: Concurrency Specification

16

Tool Support for Concurrency Analysis INCA (Inequality Necessary Condition Analysis)

– Checks properties of an architectural specification (e.g. mutual exclusion)– Provides example executions that violate those properties– Verifies that a modification removes the faults

Page 17: Concurrency Specification

17

Detecting a Race Condition

Customer1 pays before Customer2 but

Customer2 takes up the hose before

Customer1 thus getting the amount of

gas purchased by Customer1

Page 18: Concurrency Specification

18

The INCA Query

Page 19: Concurrency Specification

19

INCA Results

INCA generates a system of

inequalities based on the violation of

properties specified by the query– A consistent inequality implies such a

situation is possible– An inconsistent inequality implies such a

situation is impossible

Page 20: Concurrency Specification

20

Features Common with Other Formal Methods RSTG Pre and post conditions State invariants

Page 21: Concurrency Specification

21

Unique Features - 1

Operation execution phases– Request phase– Enabled phase– Service phase

• Only one operation invocation can be in the service

phase

– Terminate phase

Example: Fair scheduler []<>enabled(o) -> <>service(o)

Page 22: Concurrency Specification

22

Unique Features - 2 Separation of control resources from

state variables Event expressions help “walk through”

the concurrency aspect Semantics of allocation and deallocation

– Helpful in detecting deadlocks

Page 23: Concurrency Specification

23

Deadlock Checker

Performs checks on parallel programs

written in CSP in order to prove

freedom from deadlock Takes in a network file (.net) that has

been compiled from a CSP source file

using a tool such as FDR

Page 24: Concurrency Specification

24

The Dining Philosophers Problem 5 philosophers and 5 chopsticks All philosophers keep thinking When a philosopher feels hungry, he

picks up the chopsticks closest to him,

eats rice and keeps the chopsticks back Deadlock:

– When all philosophers grab their left chopstick

simultaneously

Page 25: Concurrency Specification

25

The Dining Philosophers Problem

Page 26: Concurrency Specification

26

Architectures and Concurrency Component types:

– Synchronizer– Process units

Connector– Synchronization connector

Page 27: Concurrency Specification

27

Synchronization Connector

Process unit 1 Process unit 3Process unit 2

Synchronization connector

Synchronizer

Page 28: Concurrency Specification

28

Conclusions and Discussion

Analysis of concurrent systems early in

the development process reduces

complexity and cost of correcting errors A formal analysis will help detect

deadlocks and starvation and also in

direct code generation Concurrency in software architectures can

be represented in terms of CSPs