Docsity

Concurrent Execution - Software Engineering | CEN 5035, Papers of Software Engineering

Partial preview of the text

Download Concurrent Execution - Software Engineering | CEN 5035 and more Papers Software Engineering in PDF only on Docsity!

Concurrency: concurrent execution 1

Chapter 3

Concurrent Execution

Concurrency: concurrent execution 2

Concurrent execution

Concepts: processes - concurrent execution

and interleaving. process interaction.

Models: parallel composition of asynchronous processes

  • interleaving interaction - shared actions process labeling, and action relabeling and hiding structure diagrams

Practice: Multithreaded Java programs

Concurrency: concurrent execution 4

3.1 Modeling Concurrency

u How should we model process execution speed? l arbitrary speed (we abstract away time)

u How do we model concurrency? l arbitrary relative order of actions from different processes ( interleaving but preservation of each process order )

u What is the result? l provides a general model independent of scheduling ( asynchronous model of execution)

Concurrency: concurrent execution 5

parallel composition - action interleaving

think ‡‡ talk ‡‡ scratch think ‡‡ scratch ‡‡ talk scratch ‡‡ think ‡‡ talk

Possible traces as a result of action interleaving.

If P and Q are processes then (P||Q) represents the concurrent execution of P and Q. The operator || is the parallel composition operator.

ITCH = (scratch->STOP). CONVERSE = (think->talk->STOP).

||CONVERSE_ITCH = (ITCH || CONVERSE).

Concurrency: concurrent execution 7

parallel composition - algebraic laws

Commutative: (P||Q) = (Q||P) Associative: (P||(Q||R)) = ((P||Q)||R) = (P||Q||R).

Clock radio example: CLOCK = (tick->CLOCK). RADIO = (on->off->RADIO).

||CLOCK_RADIO = (CLOCK || RADIO).

LTS? Traces? Number of states?

Concurrency: concurrent execution 8

modeling interaction - shared actions

MAKER = (make->ready->MAKER). USER = (ready->use->USER).

||MAKER_USER = (MAKER || USER).

MAKER

synchronizes with USER when ready.

If processes in a composition have actions in common, these actions are said to be shared. Shared actions are the way that process interaction is modeled. While unshared actions may be arbitrarily interleaved, a shared action must be executed at the same time by all processes that participate in the shared action.

LTS? Traces? Number of states?

Concurrency: concurrent execution 10 ©Magee/Kramer

modeling interaction - multiple processes

MAKE_A = (makeA->ready->used->MAKE_A). MAKE_B = (makeB->ready->used->MAKE_B). ASSEMBLE = (ready->assemble->used->ASSEMBLE). ||FACTORY = (MAKE_A || MAKE_B || ASSEMBLE).

Multi-party synchronization:

makeA

makeB makeA ready assemble

used

makeB

0 1 2 3 4 5

Concurrency: concurrent execution 11

composite processes

A composite process is a parallel composition of primitive processes. These composite processes can be used in the definition of further compositions.

||MAKERS = (MAKE_A || MAKE_B).

||FACTORY = (MAKERS || ASSEMBLE).

Substituting the definition for MAKERS in FACTORY and applying the commutative and associative laws for parallel composition results in the original definition for FACTORY in terms of primitive processes.

||FACTORY = (MAKE_A || MAKE_B || ASSEMBLE).

Concurrency: concurrent execution 13

process labeling by a set of prefix labels

{a1,..,ax}::P replaces every action label n in the alphabet of P with the labels a1.n,…,ax.n. Further, every transition (n->X) in the definition of P is replaced with the transitions ({a1.n,…,ax.n} ->X).

Process prefixing is useful for modeling shared resources: RESOURCE = (acquire->release->RESOURCE). USER = (acquire->use->release->USER).

||RESOURCE_SHARE = (a:USER || b:USER || {a,b}::RESOURCE).

Concurrency: concurrent execution 14

process prefix labels for shared resources

How does the model ensure that the user that acquires the resource is the one to release it?

a:USER

a.acquire a.use

a.release

0 1 2

b:USER

b.acquire b.use

b.release

0 1 2

{a,b}::RESOURCE

a.acquire

b.acquire

a.release b.release

0 1

RESOURCE_SHARE

a.acquire

b.acquire b.use

b.release

a.use

a.release

0 1 2 3 4

Concurrency: concurrent execution 16

action relabeling

||CLIENT_SERVER = (CLIENT || SERVER) /{call/request, reply/wait}.

CLIENT

call reply

continue

0 1 2

SERVER call^ service

reply

0 1 2

CLIENT_SERVER call^ service^ reply

continue

0 1 2 3

Concurrency: concurrent execution 17

action relabeling - prefix labels

SERVERv2 = (accept.request ->service->accept.reply->SERVERv2). CLIENTv2 = (call.request ->call.reply->continue->CLIENTv2).

||CLIENT_SERVERv2 = (CLIENTv2 || SERVERv2) /{call/accept}.

An alternative formulation of the client server system is described below using qualified or prefixed labels:

Concurrency: concurrent execution 19

action hiding

USER = (acquire->use->release->USER) {use}.

USER = (acquire->use->release->USER) @{acquire,release}.

The following definitions are equivalent:

acquire tau

release

0 1 2

Minimization removes hidden tau actions to produce an LTS with equivalent observable behavior. acquire

release

0 1

Concurrency: concurrent execution 20

structure diagrams

P (^) a b

Process P with alphabet {a,b}.

P (^) a m b^ Q Parallel Composition (P||Q) / {m/a,m/b,c/d}

P (^) a Q

c c d x x x

S x y

Composite process ||S = (P||Q) @ {x,y}