Advanced Programming - Concurrency, Lab 1 Advanced Programming - Concurrency, Lab 1 Aims The aim of this lab is to familiarise yourself with the LTSA (Labelled Transition Systems Analyser) tool on one hand and to try your hand at some simple models, so as to learn the FSP (Finite State Processes) language. The LTSA tool provides you with a very simple editor for writing models in the FSP language. But unlike other modelling tools (e.g., most UML ones), editing is just the first step with this tool. It can: take your model and draw it as an automaton, which looks then something like a UML statechart. tell you what actions have been specified for a process (that is, show you its alphabet). simulate/run it. even allow you to verify certain properties for it! Try starting the LTSA tool: You can download LTSA locally (e.g., on your own machine at home) and run it yourself. It is already installed in the lab Windows PCs. Here is the LTSA user manual and the FSP Quick Reference guide, which are also included at the end of your handouts. Start LTSA and write a simple model for a bomb. Someone _starts_ the timer of the bomb and that runs until the _timeout_ event. The _timeout_ is followed by the _explode_ event, at which point the behaviour of the bomb stops. So a model for the above specification would be something like:
BOMB = (start -> timeout -> explode -> STOP).
We have a process that models the bomb (called BOMB - all process names are in capital letters) - this process can engage in the start action, then in the timeout action, then in the explode action and at that point it behaves like the STOP process (which does nothing). Now from the "Build" menu option, select "Parse". This lets you know if your specification contains syntax errors. Introduce some syntax errors to see what the error messages are. For example, try deleting the dot at the end of the specification and parsing again. Now add the dot back and replace an arrow with a minus sign or delete an arrow altogether. Do you understand the error messages? If you have no syntax errors, then select "Check -> Compile". This will generate the state machine (Labelled Transition System - LTS) that corresponds to your specification. You want to see what it looks like? Select "Window -> Draw". Is this what you expected? You can also experiment with actually "animating" the model of the bomb. Select "Check -> Run -> Default". An animator window comes up. On the right, you have the actions that can be performed by the Bomb. The "ticked" ones are those that are eligible at the current state. Select an action that you would like the bomb to perform (by clicking in its corresponding box). Can all actions be selected? What happens when you select an eligible action? Does anything change on the displayed LTS? Go to "Window" and select the "Alphabet" option. Another tab is now available (along with "Edit", "Output" and "Draw"), called "Alphabet". Select that tab and see what the alphabet of the BOMB process is. Questions When the LTS is drawn, why is it that the start action leads to a state different from the initial one, the timeout to another state and the explode action to yet another one? Why don't they all lead to the same state? What would the FSP model for that be? If you consider the possible actions (start, timeout, explode), some of these are external ones that users of the bomb perform, e.g., start, while others are internal actions that the bomb itself performs, e.g., explode. How are these distinguished? Now perform all the above steps for the following specification of a lamp:
LAMP = (switch_on -> switch_off -> LAMP).
Questions Can you see an important difference from the first model? Assume that you wanted to write a Java class for this lamp. The way to interact with it is through two methods that implement the switch_on and switch_off actions. A lamp object would also need to know which state it is in, so as to know how to behave when one of its methods is called. Looking at the state diagram that the tool draws for this model, how many different states can such a lamp object have? What kind of an internal (private) variable would you need to specify in the Java class to represent these states? What should each of the two methods do?
public class Lamp {
// Variables missing
Lamp() {
// Code missing
}
public void switch_on() {
// Code missing
}
public void switch_off() {
// Code missing
}
public static void main(String [] args) {
Lamp l = new Lamp();
l.switch_on();
l.switch_off();
l.switch_off();
}
}
If you have completed the Java code for the lamp, do you understand what the states of the state diagram stand for?