Upload
doandiep
View
236
Download
0
Embed Size (px)
Citation preview
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
COMP30112: ConcurrencyTopics 2.2: Concurrency in FSP & 3.1: Java Threads
Howard Barringer
Room KB2.20: email: [email protected]
February 2008
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Parallel Composition
F Consider ‘DAY’ processes? F
(P||Q) represents the concurrent execution of P and Q.The operator || is the parallel composition operator.
LAUGH = (laugh->STOP).CONVERSE = (think->talk->STOP).
|| CONVERSE LAUGH = (LAUGH || CONVERSE).
F Possible Traces? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Parallel Composition
F Consider ‘DAY’ processes? F
(P||Q) represents the concurrent execution of P and Q.The operator || is the parallel composition operator.
LAUGH = (laugh->STOP).CONVERSE = (think->talk->STOP).
|| CONVERSE LAUGH = (LAUGH || CONVERSE).
F Possible Traces? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Parallel Composition
F Consider ‘DAY’ processes? F
(P||Q) represents the concurrent execution of P and Q.The operator || is the parallel composition operator.
LAUGH = (laugh->STOP).CONVERSE = (think->talk->STOP).
|| CONVERSE LAUGH = (LAUGH || CONVERSE).
F Possible Traces? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Interleaving Actions
LAUGH
2 states
��������0 1
laughI CONVERSE
3 states
������������0 1 2
thinkI
talkI
F Composite LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Interleaving Actions
LAUGH
2 states
��������0 1
laughI CONVERSE
3 states
������������0 1 2
thinkI
talkI
F Composite LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Example: Clock Radio
CLOCK = (tick->CLOCK).RADIO = (on->off->RADIO).
||CLOCK RADIO = (CLOCK || RADIO).
F LTS? F F Traces? F F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Example: Clock Radio
CLOCK = (tick->CLOCK).RADIO = (on->off->RADIO).
||CLOCK RADIO = (CLOCK || RADIO).
F LTS? F
F Traces? F F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Example: Clock Radio
CLOCK = (tick->CLOCK).RADIO = (on->off->RADIO).
||CLOCK RADIO = (CLOCK || RADIO).
F LTS? F F Traces? F
F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Example: Clock Radio
CLOCK = (tick->CLOCK).RADIO = (on->off->RADIO).
||CLOCK RADIO = (CLOCK || RADIO).
F LTS? F F Traces? F F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Shared Actions
• processes in a composition may have common actions: sharedactions(i.e. process alphabets intersect)
• shared actions model process interaction
• unshared actions: arbitrary interleaving
• shared actions: must be executed at the same time by allprocesses
MAKER = (make->ready->MAKER).USER = (ready->use->USER).
|| MAKER USER = (MAKER || USER).
F LTS? F F Traces? F F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Shared Actions
• processes in a composition may have common actions: sharedactions(i.e. process alphabets intersect)
• shared actions model process interaction
• unshared actions: arbitrary interleaving
• shared actions: must be executed at the same time by allprocesses
MAKER = (make->ready->MAKER).USER = (ready->use->USER).
|| MAKER USER = (MAKER || USER).
F LTS? F F Traces? F F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Shared Actions
• processes in a composition may have common actions: sharedactions(i.e. process alphabets intersect)
• shared actions model process interaction
• unshared actions: arbitrary interleaving
• shared actions: must be executed at the same time by allprocesses
MAKER = (make->ready->MAKER).USER = (ready->use->USER).
|| MAKER USER = (MAKER || USER).
F LTS? F F Traces? F
F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Shared Actions
• processes in a composition may have common actions: sharedactions(i.e. process alphabets intersect)
• shared actions model process interaction
• unshared actions: arbitrary interleaving
• shared actions: must be executed at the same time by allprocesses
MAKER = (make->ready->MAKER).USER = (ready->use->USER).
|| MAKER USER = (MAKER || USER).
F LTS? F F Traces? F F Number of states? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Handshake
Handshake is an action acknowledged by another:
MAKERv2 = (make->ready->used->MAKERv2).USERv2 = (ready->use->used->USERv2).
|| MAKER USERv2 = (MAKERv2 || USERv2).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Handshake
Handshake is an action acknowledged by another:
MAKERv2 = (make->ready->used->MAKERv2).USERv2 = (ready->use->used->USERv2).
|| MAKER USERv2 = (MAKERv2 || USERv2).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Handshake
Handshake is an action acknowledged by another:
MAKERv2 = (make->ready->used->MAKERv2).USERv2 = (ready->use->used->USERv2).
|| MAKER USERv2 = (MAKERv2 || USERv2).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Handshake
Handshake is an action acknowledged by another:
MAKERv2 = (make->ready->used->MAKERv2).USERv2 = (ready->use->used->USERv2).
|| MAKER USERv2 = (MAKERv2 || USERv2).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Handshake
Handshake is an action acknowledged by another:
MAKERv2 = (make->ready->used->MAKERv2).USERv2 = (ready->use->used->USERv2).
|| MAKER USERv2 = (MAKERv2 || USERv2).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Multiple Processes
Multi-party synchronisation:
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).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Multiple Processes
Multi-party synchronisation:
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).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Multiple Processes
Multi-party synchronisation:
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).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Multiple Processes
Multi-party synchronisation:
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).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Multiple Processes
Multi-party synchronisation:
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).
F LTS? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Labelling - I
a : P prefixes each action label in the alphabet of P with a.Two instances of a switch process:SWITCH = (on->off->SWITCH).|| TWO SWITCH = (a : SWITCH || b : SWITCH).
An array of instances of the switch process:||SWITCHES(N = 3) = (forall[i : 1..N] s[i] : SWITCH).||SWITCHES(N = 3) = (s[i : 1..N] : SWITCH).
F Write SWITCHES(3) in basic FSP? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Labelling - I
a : P prefixes each action label in the alphabet of P with a.Two instances of a switch process:SWITCH = (on->off->SWITCH).|| TWO SWITCH = (a : SWITCH || b : SWITCH).
An array of instances of the switch process:||SWITCHES(N = 3) = (forall[i : 1..N] s[i] : SWITCH).||SWITCHES(N = 3) = (s[i : 1..N] : SWITCH).
F Write SWITCHES(3) in basic FSP? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Labelling - I
a : P prefixes each action label in the alphabet of P with a.Two instances of a switch process:SWITCH = (on->off->SWITCH).|| TWO SWITCH = (a : SWITCH || b : SWITCH).
An array of instances of the switch process:||SWITCHES(N = 3) = (forall[i : 1..N] s[i] : SWITCH).||SWITCHES(N = 3) = (s[i : 1..N] : SWITCH).
F Write SWITCHES(3) in basic FSP? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Labelling - II
{a1, . . . , ax} :: P replaces every action label n in the alphabet of Pwith the labels a1.n, . . . , ax.n. Further, every transition n->X inthe 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).
F Write RESOURCE SHARE in basic FSP? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Labelling - II
{a1, . . . , ax} :: P replaces every action label n in the alphabet of Pwith the labels a1.n, . . . , ax.n. Further, every transition n->X inthe 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).
F Write RESOURCE SHARE in basic FSP? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Labelling - II
{a1, . . . , ax} :: P replaces every action label n in the alphabet of Pwith the labels a1.n, . . . , ax.n. Further, every transition n->X inthe 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).
F Write RESOURCE SHARE in basic FSP? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Prefix Labels For Shared Resources
F LTS for RESOURCE SHARE? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Process Prefix Labels For Shared Resources
F LTS for RESOURCE SHARE? F
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Action Relabelling - I
Relabelling functions are applied to processes to change the namesof action labels. The general form of the relabelling function is:
/{newlabel1/oldlabel1 , . . . , newlabeln/oldlabeln}.
Relabelling to ensure that composed processes synchronize onparticular actions:CLIENT = (call->wait->continue->CLIENT).SERVER = (request->service->reply->SERVER).
|| CLIENT SERVER = (CLIENT || SERVER)/{call/request, reply/wait}.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Action Relabelling - I
Relabelling functions are applied to processes to change the namesof action labels. The general form of the relabelling function is:
/{newlabel1/oldlabel1 , . . . , newlabeln/oldlabeln}.
Relabelling to ensure that composed processes synchronize onparticular actions:CLIENT = (call->wait->continue->CLIENT).SERVER = (request->service->reply->SERVER).
|| CLIENT SERVER = (CLIENT || SERVER)/{call/request, reply/wait}.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Client Server LTSs
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Action Relabelling - II
Alternative formulation of the client server system is describedbelow using qualified or prefixed labels:SERVERv2 = (accept.request
->service->accept.reply->SERVERv2).CLIENTv2 = (call.request
->call.reply->continue->CLIENTv2).
|| CLIENT SERVERv2 = (CLIENTv2 || SERVERv2)/{call/accept}.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Action Hiding
When applied to a process P, the hiding operator\{a1..ax} removes the action names a1..ax from thealphabet of P and makes these concealed actions“silent”. These silent actions are labelled tau. Silentactions in different processes are not shared.
Sometimes it is more convenient to specify the set of labels to beexposed...
When applied to a process P, the interface operator@{a1..ax} hides all the actions in the alphabet of P notlabelled in the set a1..ax.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Action Hiding
When applied to a process P, the hiding operator\{a1..ax} removes the action names a1..ax from thealphabet of P and makes these concealed actions“silent”. These silent actions are labelled tau. Silentactions in different processes are not shared.
Sometimes it is more convenient to specify the set of labels to beexposed...
When applied to a process P, the interface operator@{a1..ax} hides all the actions in the alphabet of P notlabelled in the set a1..ax.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
The following definitions are equivalent:USER = (acquire->use->release->USER)
\{use}.USER = (acquire->use->release->USER)
@{acquire, release}.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Summary
• process composition e.g. (P || Q || R)
• shared actions synchronised• unshared actions interleaved
• process labeling e.g. a : P and {a,b} :: P
• action relabelling e.g. P/{a/b, c/d}• action hiding e.g. P\{a,b} and P@{c,d}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Summary
• process composition e.g. (P || Q || R)• shared actions synchronised
• unshared actions interleaved
• process labeling e.g. a : P and {a,b} :: P
• action relabelling e.g. P/{a/b, c/d}• action hiding e.g. P\{a,b} and P@{c,d}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Summary
• process composition e.g. (P || Q || R)• shared actions synchronised• unshared actions interleaved
• process labeling e.g. a : P and {a,b} :: P
• action relabelling e.g. P/{a/b, c/d}• action hiding e.g. P\{a,b} and P@{c,d}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Summary
• process composition e.g. (P || Q || R)• shared actions synchronised• unshared actions interleaved
• process labeling e.g. a : P and {a,b} :: P
• action relabelling e.g. P/{a/b, c/d}• action hiding e.g. P\{a,b} and P@{c,d}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Summary
• process composition e.g. (P || Q || R)• shared actions synchronised• unshared actions interleaved
• process labeling e.g. a : P and {a,b} :: P
• action relabelling e.g. P/{a/b, c/d}
• action hiding e.g. P\{a,b} and P@{c,d}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Summary
• process composition e.g. (P || Q || R)• shared actions synchronised• unshared actions interleaved
• process labeling e.g. a : P and {a,b} :: P
• action relabelling e.g. P/{a/b, c/d}• action hiding e.g. P\{a,b} and P@{c,d}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
The Thread Class
class MyThread extends Thread {int i;
public void run() {i = 0;while (i <= 5) {System.out.println("" + i);i++;
}}}
...MyThread mt = new MyThread();mt.start();...
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
The Runnable Interface
public interface Runnable{
public abstract void run();
}
class MyRun implements Runnable {
int i;
public void run() {
i = 0;
while (i <= 5) {
System.out.println("" + i);
i++;
}}}
...
MyRun mr = new MyRun();
Thread mt = new Thread(mr);
mt.start();
...
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Terminal Counter
class Counter implements Runnable {
Thread counter; int i;final static int N = 3;
Counter () {counter = new Thread(this);i = N;counter.start();
}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Terminal Counter - cont.
public void run () {while (true) {if (counter == null) return;if (i>0) {System.out.println("Count is " + i);try { Thread.sleep(500); }catch (InterruptedException e) {}i--;
}if (i==0) {System.out.println("Count is done");return;
}}//while
}//run }//class
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
class CounterText {
public static void main (String [] args) {
System.out.println("Main starting counter...");Counter count = new Counter();System.out.println("Main Done");
}//main}//class CounterText
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Thread Synchronisation
synchronized (obj) statements
synchronized typename methodname () statement
This provides mutually exclusive access to methods/objects.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
• each object has a single lock associated with it
• any synchronized code applied to an object must firstobtain the lock for the object
• if the lock is already taken, then thread will block until lock isavailable
• exception releases lock
• scheduling policy for waiting threads
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
wait() and notify()
• wait(): suspend and block thread; release lock
• notify(): unblock a suspended thread
• notifyAll(): unblock all suspended threads
• wait sets
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Condition Synchronization
synchronized type1 Method1 (...)throws InterruptedException {
while (!firstCondition){ wait(); }...
}
synchronized type2 Method2 (...) {...firstCondition = true;notify(); // or notifyAll()...
}
Note: signal-and-continue semantics for notify()
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Car Park
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Car Park Control Class
class CarParkControl {
protected int spaces;
protected int capacity;
CarParkControl(int n) {
capacity = spaces = n;
}
synchronized void arrive() throws InterruptedException {
while (spaces==0) wait();
--spaces;
notifyAll();
}
synchronized void depart() throws InterruptedException{
while (spaces==capacity) wait();
++spaces;
notifyAll();
}
}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Car Park Arrivals class
class Arrivals implements Runnable {
CarParkControl carpark;
Arrivals(CarParkControl c) {
carpark = c;
}
public void run() {
try {
while(true) {
ThreadPanel.rotate(330);
carpark.arrive();
ThreadPanel.rotate(30);
}
} catch (InterruptedException e){}
}
}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Car Park Departures class
class Departures implements Runnable {
CarParkControl carpark;
Departures(CarParkControl c) {
carpark = c;
}
public void run() {
try {
while(true) {
ThreadPanel.rotate(180);
carpark.depart();
ThreadPanel.rotate(180);
}
} catch (InterruptedException e){}
}
}
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Outline
Topic 2.2: Modelling Processes with FSP - IIComposing Processes in ParallelInteractionLabelling ProcessesRelabelling & HidingSummary
Topic 3.1: Java Threads: RevisionThreadsExampleSynchronisationExampleThread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Thread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Thread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
Thread Lifecycle
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
FSP for Thread Lifecycle
THREAD = CREATED,
CREATED = (start ->RUNNING
|stop ->TERMINATED),
RUNNING = ({suspend,sleep}->NON_RUNNABLE
|yield ->RUNNABLE
|{stop,end} ->TERMINATED
|run ->RUNNING),
RUNNABLE = (suspend ->NON_RUNNABLE
|dispatch ->RUNNING
|stop ->TERMINATED),
NON_RUNNABLE = (resume ->RUNNABLE
|stop ->TERMINATED),
TERMINATED = STOP.
Topic 2.2: Modelling Processes with FSP - II Topic 3.1: Java Threads: Revision
LTS for Thread Lifecycle