Specific Proposals For The Use of Petri Nets in A
Specific Proposals For The Use of Petri Nets in A
net/publication/220808530
Specific proposals for the use of petri nets in a concurrent programming course
CITATIONS READS
2 1,560
1 author:
SEE PROFILE
All content following this page was uploaded by Joao Paulo Barros on 27 May 2014.
Permission to make digital or hard copies of all or part of this work for 2. THE COURSE
personal or classroom use is granted without fee provided that copies are
not made or distributed for profit or commercial advantage and that
The course follows the referred book [3] which is used as the
copies bear this notice and the full citation on the first page. To copy main reference. As such, in each course section we also present
otherwise, or republish, to post on servers or to redistribute to lists, concepts prior to models and these prior to coding. We present
requires prior specific permission and/or a fee. UML class and object diagrams, FSP and Java concurrent
ITiCSE’02, June 24-26, 2002, Aarhus, Denmark. constructs. Java is used due to its current popularity and included
Copyright 2002 ACM 1-58113-499-1/02/0006…$5.00. support for concurrency, namely monitors.
165
2.1 Assessment 3.1 Synchronization and Deadlock
Student assessment is based on a semester long project and an Synchronization is clearly visualized in almost any Petri net. Here
open book written exam. we propose the use of Petri nets to visualize a deadlock initial
state. This section uses the FSP model from an exercise proposed
The project implies analyse, design and coding of a simple
in [3] as an example of the added advantage on the use of Petri
concurrent system containing a few processes. These are coded as
nets for better understanding of concurrency concepts. In this case
Java Threads. Students are required to use UML, FSP, Petri nets
the concepts are synchronisation and a deadlock resulting from a
and Java. We also encourage the generation of project
“wait-for cycle”. The FSP model, containing three primitive
documentation, namely UML class diagrams and source code
processes (“Alice”, “Bob” and “Chris”) and one composite
documentation.
process (“S”), is the following:
The written exam presents some simple concurrent systems and Alice = (call.bob -> wait.chris -> Alice).
asks for FSP specifications and/or Petri nets models. It also Bob = (call.chris -> wait.alice -> Bob).
explores safety and liveness properties. Chris = (call.alice -> wait.bob -> Chris).
166
wait.bob Consider the following FSP model that specifies a simple
call.bob semaphore with states red and green.
CLOCK = (tick -> CLOCK).
call.bob
CLOCKL(N = 2) = (start -> LG[0]),
LG[lg:0..6] = (when (lg < N) tick -> LG[lg+1]
wait.chris
|when (lg == N) long_tick ->
CLOCKL).
|| LONG_CLOCK = (CLOCK || CLOCKL).
call.chris wait.chris
SEMAPHORE_GREEN = (change_to_red ->
call.chris
SEMAPHORE_RED),
SEMAPHORE_RED = (change_to_green ->
SEMAPHORE_GREEN).
The semaphore is controlled by a process “CLOCK”, that
wait.alice generates an action named “tick”, and a “CLOCKL” process, that
call.alice
generates a “long_tick” action after two “tick”. The process
wait.alice “LONG_CLOCK” is a composite of “CLOCK” and “CLOCKL”.
call.alice
The “SEMAPHORE_GREEN” process specifies the light change.
The timing is to be imposed by the composition of
“SEMAPHORE_GREEN” with one or more “CLOCK” and/or
“LONG_CLOCK” processes. The semaphore should change to
wait.bob
red after one “tick” in green and change to green after one
Step 1/3: Translation Step 2/3: Grouping of “long_tick” in red.
from state-machines to synchronized
Petri nets notation transitions. A first attempt could be:
||SEMAPHORE_TIMED = (SEMAPHORE || LONG_CLOCK)
Figure 2. From parallel state machines to Petri nets. The /{change_to_red/tick,
figure illustrates the first two of a total of three steps. change_to_green/long_tick}.
A brief look at this Petri net makes clear that the system is Unfortunately, this does not work. The “change_to_red” action
deadlocked as no transition can fire. This results from each will consume one “tick” that should be used by the
transition dependency on an unmarked place on the right. “change_to_green” (“long_tick”). As such the semaphore will be
bob
one single “tick” in the red state instead of two. To avoid this
problem we can try to add one CLOCK process to the composite:
||SEMAPHORE_TIMED = (SEMAPHORE_GREEN ||
LONG_CLOCK ||
CLOCK)
/{change_to_red/tick,
chris change_to_green/long_tick}.
This has a new, more subtle, problem: we have one more process
“CLOCK”, besides the one “inside” “LONG_CLOCK”, but it
remains synchronized with the “LONG_CLOCK”. As such we
have not made any progress yet. This is much more obvious in the
alice Petri net model (Figure 4).
CLOCK
RED
Figure 3. From parallel state machines to Petri nets. The GREEN
figure illustrates the last of a total of three steps. SEMAPHORE_GREEN
Next we present a more elaborate example emphasizing process change_to_green = long_tick
composition understanding.
2 2
167
It is enough to observe that after the firing of the transition interleaving and, by consequence, the state explosion problem,
associated to actions “change_to_red” and “tick”, the net will but it has the cost of making unclear the dependencies between
deadlock as no transition will be enabled. Students can observe processes, namely their synchronisations. Even the parallelism is
this behaviour using the mentioned Petri net tool, or any other not clear as the interleaving hides it under the states representing
tool that allows token-game graphical simulation, will be combinations of more than one state in the original state
adequate. machines. By contrast, a Petri net allows a clear visualization not
At this point most students will realize by themselves that the only of the initial state machines (which are just a particular case
problem is the “use” of process CLOCK by process of a Petri net) but also of the parallel composition and respective
LONG_CLOCK. From this a possible solution is quite obvious: synchronisations.
LONG_CLOCK should use a different CLOCK (labelled “a” in
a:CLOCK
the following code):
||SEMAPHORE_TIMED = (SEMAPHORE_GREEN ||
LONG_CLOCK ||
a:CLOCK)
/{change_to_red/a.tick, change_to_red = a.tick = start
change_to_green/long_tick}.
GREEN RED
4. EVALUATION
The presented examples were used in one edition of the referred
tick
introductory concurrent programming course; two previous
editions had used preliminary versions of those same examples. In
the course we had 16 students. About half the students had one
LONG_CLOCK year experience using the Java language in an academic setting;
the others had zero or negligible experience programming Java or
CLOCK any other object-oriented programming language. Most of them
had been exposed to concurrent programming only in an
Figure 5 Petri net for FSP model with one more clock. operating systems course through the study of trivial concurrent
The final Petri net only starts the LONG_CLOCK process on programs written in the C programming language and using
arrive to state RED (Figure 6). UNIX system calls.
Note that the composite state machine, generated by the LTSA
tool, contains all the interleavings allowed by the
synchronisations. This is very useful to understand the concept of
168
The inquiry clearly showed that students found the addition of
Petri nets useful particularly in the understanding of concepts.
They did not found Petri nets models to be easier to build than
FSP models, but the majority found easier to start by the Petri net
model as opposed to the FSP model. Also, most of the students
found that the Petri net model helped them to understand the Java
programs. These results confirmed our feedback from the class,
namely that the presented usage of Petri nets improves students
understanding of concurrent programs and concurrency concepts.
7. REFERENCES
Table 1. Answers to the questionnaire given to students.
[1] Ben-Ari, M. “Principles of Concurrent Programming”,
Average in Prentice-Hall, 1982.
Question a Likert
scale (1-5) [2] Jensen, K. e Rozemberg(Eds.) High-level Petri Nets:Theory
and Application, Springer-Verlag, 1991.
Petri nets allowed a better understanding of process 4.3
composition [3] Magee, Jeff, Kramer, Jeff, “Concurrency State Models and
Petri nets allowed a better understanding of the starvation 4.4
Java Programs”, John Wiley & Sons, 1999.
and deadlock concepts
[4] Petri Net Tools, http://www.daimi.au.dk/PetriNets/tools/.
Overall, Petri nets allowed a better understanding of 4.4
concurrent systems operation [5] Reisig, Wolfgang, “Elements of Distributed Algorithms –
The construction of FSP models PLUS Petri nets, helped Modeling and Analysis with Petri Nets”, Springer, 1998.
4.4
the understanding of concepts and concurrent systems
Petri net models are easier to understand than FSP models 3.8
Petri net models are easier to build than FSP models 3.3
It is easier to start by doing the Petri net model rather than 3.7
by the FSP model
Petri net models make Java programs easier to 3.8
understand.
169