CPDS Notes UPC

Couldn't load preview image :\

Context

Concurrency

Labeled Transition System (LTS)

A Labeled Transition System (LTS) is a mathematical model used to represent the behavior of concurrent and reactive systems. It’s a formal way to describe how a system moves between different states based on actions or events.

An LTS is formally defined as a tuple: LTS = (S, A, β†’, sβ‚€)

Where:

S = Set of states
A = Set of action labels (alphabet)
sβ‚€ = Initial state

β†’ = Transition relation (subset of S Γ— A Γ— S)

Means: β€œFrom state s, action a leads to state s’”

Lets draw an example. For that we should declare the rules of the program:

S = {HUNGRY, EATING}
A = {getserving, digest}
sβ‚€ = HUNGRY

Transitions:
HUNGRY --getserving--> EATING
EATING --digest--> HUNGRY

We can now proced with the drawing of the program to visualize its behavior. If done correctly, the drawing should represent exactly the program behavior.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  getserving  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ HUNGRY  β”‚ ────────────>β”‚ EATING  β”‚
β”‚   sβ‚€    β”‚              β”‚         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      ↑                        β”‚
      β”‚         digest         β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

This has been done manually and of course we could make mistakes in the process. For this reason there are tools like LTSA that automate the drawing process based on some β€œmathematicall notation”. In this course we used FSP notation. It is limited to finite state process and it looks like:

SAVAGE = HUNGRY,
HUNGRY = (getserving -> EATING),
EATING = (digest -> HUNGRY).

LTSA program can then read this notation, draw the program, show alerts such as deadlocks and allow for simple simulations.

fig 1: Basic LTSA example
fig 1: Basic LTSA example

FSP Nomenclature

fig 2: Non-deterministic choice
fig 2: Non-deterministic choice
fig 3: Calculator example
fig 3: Calculator example

Modeling concurrency

As we know, concurrency refers to the ability of a computing system to make progress on multiple tasks during the same time period, allowing different parts of a program to run independently or be interleaved.

We are creating mathematical models to represent a concurrent process (some kind of theoretical implementation) to test if it holds on the real world and point out the possible errors they can throw.

This two strategies on an LTS mathematical model offer a general model independent of OS scheduling strategies and asynchronous model of execution.

We will proceed now to show how to implement Arbitrary speed and Arbitrary relative order of actions:

Modeling Parallel Composition / action interleaving

As mentioned above we must design some kind of communication between processes. In FSP we accomplish this with Parallel Composition:

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

the characters || corresponds to the parallel composition operator. If P and Q are processes then (P||Q) represents the concurrent execution of P and Q.

This processes can now be called on parallel but they are not communicating each other, they are independent. We will talk about shared actions in β€œModeling Interaction” chapter.

Modeling Interaction

In concurrent systems, interaction between processes is often modeled using shared actions. When two or more processes have actions with the same label, those actions are considered shared and must occur simultaneously in all participating processes. Unshared actions, on the other hand, can be interleaved arbitrarily.

Example: Maker and User

Consider two processes: a MAKER that manufactures an item and a USER that consumes it. The MAKER signals the item is ready via a shared action ready. The USER can only use the item after receiving this signal.

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

Here, ready is a shared action. Both processes must synchronize on ready before proceeding. The LTS Analyzer tool can visualize this interaction by composing the processes and drawing the resulting state diagram.

This approach ensures correct coordination between concurrent processes, preventing issues like using an item before it is ready.

More Complex Action Sharing

Example 1: Handshake

Suppose both the MAKER and USER now synchronize not only on ready, but also on used:

MAKERv2 = (make -> ready -> used -> MAKERv2).
USERv2  = (ready -> use -> used -> USERv2).
||MAKER_USERv2 = (MAKERv2 || USERv2).

Explanation:


Example 2: Multi-party synchronization

Now consider a factory with two makers and an assembler:

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).

Explanation:


Key Principle:
When multiple processes share actions, those actions act as synchronization points. The system enforces that all involved processes must be ready to perform the shared action before any can proceed, ensuring correct sequencing and coordination in concurrent systems.

Manual construction of the LTS

Concurrency in Java

Java allows to create concurrent programs when following certain rules. To translate an LTS or FSP programm to a real programming language we will have to make use of some creativity and follow certain rules to make good implementations.

Earlang