HAL Id: hal-02310048
https://hal.archives-ouvertes.fr/hal-02310048
Submitted on 10 Oct 2019
HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.
L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.
FIFO Buffers in tie Sauce
Franck Pommereau
To cite this version:
Franck Pommereau. FIFO Buffers in tie Sauce. Distributed and Parallel Systems, Sep 2000, Balaton- füred, Hungary. pp.95-104, �10.1007/978-1-4615-4489-0_13�. �hal-02310048�
FrankPommereau
LACL,UniversitéParis12,
61avenueduGénéraldeGaulle,
94010Créteil, Frane
pommereauuniv-paris12.fr
Abstrat. This paperintrodues a new semantisfor FIFObuers ina parallel programming
language, B(PN) 2
. Thissemantisis given in the algebraof M-nets, whih is a proess algebra
withasemantisintermsoflabelledhigh-levelPetrinets.Theproposedsemantismakesusageof
newlyintroduedasynhronouslinkoperatorandrepairssomedrawbaksoftheprevioussemantis:
hannelsarenowfullyexpressiblewithinthealgebra,theyareonsiderablysmaller,andtheyoer
severalotheradvantages.
Keywords.Parallelprogramming,Petrinets,proessalgebras,FIFObuers,semantis.
B(PN) 2
[2℄isa general purposeparallel programming language provided withfeatureslike par-
allel omposition, iteration, guarded ommands, ommuniations through FIFO buers (more
usually alledhannels) or shared variables,proedures[4℄ and,more reently,real-time exten-
sionswithabortable bloksand exeptions[6℄.
The semantis of B(PN) 2
is traditionally given interms of Petri nets, using a low-level nets
algebra alled Petri Box Calulus [1℄ or its high-level version, M-nets [℄. These two levels are
related by an unfolding operation whih transforms an M-net in a low-level net having an
equivalent behaviour.Inthispaper,wefousonM-netsemantis sineitismuhmoreompat
and intuitive.
Using PEP toolkit [3℄,one mayinput a B(PN) 2
program and automatially generate its M-
netsemantis for simulationpurposeorthelow-levelunfolded netinorderto model-hekones
program againstsome properties.
The purpose of this paper is to propose a new M-net semantis for hannels in B(PN) 2
.
This semantis uses asynhronous links apabilities newly introdued in M-nets an Petri Box
Calulus [5℄.Theproposedsemantis hasthreemain advantages:it isompletely expressiblein
fortheexistingsemantisand nally,itavoidstheavailabilitydefet oftheexistingsemantis
(a messagesentto a hannelwasnot immediately available for reeiving).
B(PN) 2
ispresentedin[℄and itsM-netsemantis isfullydevelopedin[℄.Inthefollowing,we
fousontheintuition inorderto keep thepaperompat but asompleteaspossible.
M-nets primer
M-nets form a lass of labelled high-level Petri nets whih were introdued in [℄ and are now
widelyusedasasemantidomainforonurrentsystemsspeiations,programminglanguages
orprotools[℄.ThemostinterestingfeaturesofM-nets,withrespettootherlassesofhigh-level
Petri nets, is their full ompositionality, thanks to their algebrai struture. Asa onsequene,
an M-netisbuilt out of sub-netswitharbitraryhand-made nets asbaseases.
AplaeinanM-netislabelledwithitstype (asetofvalues)whihindiatesthetokensitmay
hold. (In order to dene an algebra over M-nets, eah plae also has a status infe ;i;xg whih
reetswhetheritisanentry,aninternal oranexit plae.Thispartiularpointisnotruialfor
ourpurpose.)Ontheotherhand,atransitiontislabelledwithatriple(t):(t):(t)where(t)
ontains(synhronous)ommuniationations,(t)holds(asynhronous)linksannotationsand
(t) is a guard whih is a ondition for allowing or not the ring of t. Finally,ars are simply
labelled bymulti-setsof valuesor variables,indiating what they transport.
When a transition t res, variables inits annotation and on its surrounding ars are bound
to values, aording to the tokens atually available inits input plaes and with respetto its
guard (t). Transition t is allowed to re only if suh a oherent binding an be found using
available tokens. Whenre ours, tokens areonsumed and produed oherently with respet
to the hoosen binding.
M-nets algebra provides various operators for ow ontrol and ommuniations setup asde-
sribed ingure1.Letus givemore details about ommuniations.
Soping isthe normal mean to perform synhronous ommuniations between transitions in
an M-net. Figure 2 gives an illustration of soping in a trivial ase: in M-net N, transition
t
1
performs an ation A(x) and t
2 an
b
A(y); the M-net resulting from soping [A[ :N℄℄has one
transitiont
1 t
2
whih isa mixof t
1 and t
2
suh thatx andy are unied(here to x) inorderto
N
1
;N
2
sequene N
1
runsthenN
2 does
N1kN2 parallelomposition N1runsinonurrene withN2
N1 N2 hoie N1orN2 runsbutnotboth
[N
1 N
2 N
3
℄ iteration N
1
runsone(initialization), thenN
2
runszero or moretimes
(iteration)andnallyN3 runsone(termination)
[
[ A:N℄℄ soping sets-upsynhronousommuniationsbetweentransitions
Ntieb asynhronouslinks linkstransitionsasynhronously
Fig.1.OperatoronM-nets
.
.
e:f1;2g
t1 fA(x)g:;:;
x:fg x
e:fg
t2
f b
A(y)g:;:;
x:f1;2g
y
M-netN
.
.
e:f1;2g
x:fg
e:fg
x:f1;2g t
1 t
2
;:;:;
x
x
M-net[A[ :N℄℄
Fig.2.Anexampleofsoping.(xandyhavebeenuniedtox.)
possiblewhenx=y.)Inamoreomplex M-net,sopingisperformedpairwise,betweenouples
of transitionssuh ast
1 and t
2
.Inthegeneral ase, annotations aremulti-sets ofations.
Asynhronouslinks areavailablethroughlinks annotations.A transitionmayexport anitem
x ona link symbol bthanksto alink b +
(x), suh an exporteditem maybe imported later with
a link b (y). (Here again, x and y may be onstants or variables.) Figure 3 gives an example
of a basi asynhronous ommuniation between two transitions. In amore omplex M-net N,
their would be also asingle plaes
b
for all thelinks onb (there isonly one plae s
b
for Ntieb
but later, there may be new ones ifNtieb isreused ina ontext withnew links on b) and all
thetransitionsinN withalinkb +
(x)(resp.b (y))wouldbeattahedanarto (resp.from) s
b .
Likefor synhronous ommuniation ations, annotations areatually multi-sets of links.
In order to give a type to the plaes added by operator tie, eah linksymbolb is assoiated
a type whih beomesthe type of anyplae reated by anappliation of tieb.
To onlude on ommuniations, let us add that it is possible to perform synhronous and
asynhronous ommuniations on the same transition. We will see an example of this in the
proposed semantis for hannels. Notie also that soping and asynhronous links being om-
0 0
.
.
e:f1;2g
t1
;:fb +
(x)g:;
x:fg x
e:fg
t2 ;:fb (y)g:;
x:f1;2g
y
M-netN
.
.
e:f1;2g
t1
;:;:;
x:fg x
e:fg
t2
;:;:;
x:f1;2g
y i:f1;2g
s
b x
y
M-netNtieb
Fig.3.Anexampleofasynhronouslink(bhastypef1;2g)
.
.
e:fg
t (t):(t):(t)
x:fg
Fig.4.AsimpleM-net,denotedby(t):(t):(t)inthispaper.
program::=programblok (mainprogram)
blok ::=beginsopeend (blokwithprivatedelarations)
sope ::=om (arbitraryommand)
|vardel;sope (variableorhanneldelaration)
|prodel;sope (proeduredelaration)
vardel ::=varident set (variabledelaration)
|varident hankofset (hanneldelaration)
Fig.5.AfragmentofthesyntaxofB(PN) 2
(prodelandomarenotdetailedhere).
In the following, in order to avoid many gures, we will denote by (t):(t):(t) an M-net
witha lonely transitiont annotated by(t):(t):(t) and having only one input plae and one
outpu plae,both oftype fg (seegure4).
B(PN) 2
and its M-net semantis
Figure 5 gives a fragment of the syntax of B(PN) 2
, semantis is given ompositionally and is
guided by syntax: it exists a funtion Mnet whih gives its semantis to eah fragment of a
B(PN) 2
program and whose denition is reursive on the syntax. Base ase is either for an
atomiation,givingan M-netlikeon gure4where twouldbe labelled inordertoimplement
theation, or a delaration whihsemantis isgiven usingsome speialhand-made ressoure
M-nets (like for hannels innext setion).
2
keptloal to the blok)and ontinue witha ommand (whih may ontain sub-ommands and
possiblynestedbloks).Eahblokmaydelare itsownvariablesor hannels (orproedures): a
variableisnamedwithanidentierident andtakesitsvaluefromtheset giveninitsdelaration;
a hannel is delared similarly but with an additional apaity k, it may be 0 for handshake
ommuniation, k 2N for a k-bounded hannel or 1for an unbounded apaity.
The semantis for suhablokisobtained fromthesemantisof itsomponents: we justput
inparalleltheM-netfor theommand andtheM-netfor allthedelarations;thenwesope on
ommuniation ations in order to make theommuniations between omponents atual and
private. There is an additional termination net whih is added in sequene to the ommand
and whose goalis to terminate the nets for thedelarations: terminating suha netonsistsin
removing all its tokens inorder to make it lean for a possible re-usage. The semantis of any
delared ressoure X ontains atransition with anation
X
t
whih performs theemptying,so
thetermination netjustonsistsinaparallel ompositionof M-netssuhasfX
t g:;:;.
In thefollowing setion, we showand disuss urrent semantis for ahannel delaration.
Existing hannels in B(PN) 2
ChannelsforB(PN) 2
wereproposedin[℄withtheM-netsemantisdepitedingure6.Thereis
atuallythreesemantis,dependingonapaitykforthehannel.Threeationsareavailablefor
a blokwhih delares ahannel C (regardless to is apaity):
C!for sending,
C?for reeiving
and
C
t
for terminating it when the program leaves the blok. In order to ommuniate with
thehannel, the M-netwih implements theprogram arryationsC!or C?.Ation C
t
an be
found intheassoiated termination net.
In gure 6, transitions are named oherently on M-nets N
0 , N
1
and N
k
so, exepted when
speied,thefollowing desriptionis generi.
Ontransitiont
1
,the rstationonthehannelan beperformed.For N
0
thismeans sending
(with an ation C! in the program) and reeiving (ation C?) on the same transition (it is
handshakeommuniation),theguardensuresthattheommuniationisatual;forN
1 andN
k
we justhave to putone valueinthehannel.
Transitionst
2 andt
0
2
areforsendingandreeiving.InN
0
,likefort
1
,bothationareperformed
onthesametransitiont .ForN orN ,theseationsareseparated.InN weuseavalue"62set
.
.
e:fg
t1 f
C!(x);
C?(y)g
:;:fx=y2setg
i i:fg
t2 f
C!(x);
C? (y)g
:;:fx=y2setg
t3
f
C
t g:;:;
x:fg t
0
3 f
C
t g:;:;
M-netN
0
.
.
e:fg
t1
f
C!(x)g:;:fx2setg
i i:set℄f"g
x
t2 f
C!(x)g:
;:fx2setg
x
"
t 0
2
f
C? (y)g:
;:fy6="g
"
y
t3
f
C
t g:;:;
x
x:fg
t 0
3 f
C
t g:;:;
M-netN
1
.
.
e:fg
t
1 f
C!(x)g:;:fx2setg
i
1 i:set
k
x
t2 f
C!(x)g:;:
fsize(ol dl ist)<k;
newl ist=ol dl ist:xg
ol dl ist newl ist
i
2
i:set℄f"g
"
t4
;:;:
fl ist=head:tail ;
size(head)=1g l ist
tail
"
head
t 0
2 f
C?(y)g:
;:fy6="g y
"
t3
f
C
t g:;:;
l ist
y
x:fg
t 0
3 f
Ctg:;:;
M-netN
k
Fig.6.ExistingsemantisforahanneldelarationvarChankofset.Handshakeommuniation(apaity
k=0)isshownonthetopleft,for k=1weusetheM-netonthetoprightandtheM-netofthebottomisfor
k>1,inludingk=1.
todenoteanemptyhannel,annotationsonarsensurethatonevalueanbewroteonlyifplae
iholds value".Theguardsensurethatonlyvaluesinset arestoredinthehannelandthat"is
neverread.For N
k
,thesituation ismore omplexsinethequeuethatahannelatuallystores
is enoded into tokens strutured has k-bounded lists. These lists are stored in i
1
(type set k
ontainsallsequenesofatmostk valuesfromset,plusanadditional"fortheemptysequene).
Transition t
2
addsonevalueatthe endof thelistandthere isanadditionaltransitiont
4 whose
goal is to extrat the head of the list and to store it in i
2
(onlyif it holds an "); on the other
side,transitiont 0
2
islike t 0
2 inN
1 .
Transitions t
3 and t
0
3
areforhannels termination (whenever they have been usedor not).
For N , itiseasy to see thatthemehanismis quiteomplex sine itrequireslist manipula-
tions. And unfortunately, k-bounded hannels areertainly the most ommonly used... Addi-
tionally, we an point out animportant drawbakin N
k
:theprogram hasto waitfor t
4 to re
beforeitan reeive a valuewhihyet hasbeen sent to thehannel.
Wewillseeinthefollowingsetionthattheseproblemsaresolvedinoursemantisofhannels.
Letus onludeurrentsetionwitharemarkon theunfolding.WealreadysaidthatanyM-
netanbeunfoldedintoalow-levelequivalent;itisalabelledplae/transitionnetwiththeonly
available token value being .Asfar asplaes areonerned, theunfolding operation produes
one low-level plaefor eah possible value of eahplae inthe M-net. Asa diretonsequene,
unfolding M-net N
k
leads to 1+jsetj k
plaes justfor i
1
; theother plaes unfoldin either1 or
1+jsetj low-level plaes. So we an state that thenumber of plaes inthe unfolding of M-net
N
k
is O(jsetj k
).
A new semantis for hannels
First of all,let us eliminate thease of handshake ommuniations:the semantis for this par-
tiularase remains the same.For a hannel C,itan be expressedasthefollowing M-net:
f
C
t g:;:;
h
f
C! (x);
C?(y)g:;:fx=y2setg f
C!(x);
C? (y)g:;:fx=y2setg f
C
t g:;:;
i
(As explained before, notations asf
C
t
g:;:; stand for an M-net like on gure 4 with theorre-
spondinglabel onits transition.)
For boundednon-zero apaities(1k <1),we willuseasingleM-net, parametrizedbyk.
Inorderto avoidlistshandling,the stored values arenumberedmodulusk andtheM-nettakes
areto rememberthenumbers for thenextvalueto sendand, separately,thenext to reeive.
Inordertoboundapaity,weannotuseasingleounter,sharedbythesendingandreeiving
ations, whih would ount how many values are stored at a given moment: this would forbid
onurrentsendingsandreeivingssineaessingtothisounterwouldbeaonitonaplae.
Insteadofthis,weuseaolletionoftokens,oneforeahpossiblevalueinthehannel,whihare
onsideredastiketsforsending ortiketsforreeiving:inordertostoreavalue,atransition
musttakeatiket,ifnoneisavailable,thensendingisimpossible.Eahsendtransformsatiket
for sending into atiketforreeiving andsymmetrially.So whenoneation (saysending)is
to onvert one of its tikets (here itmeans that thehannel is not full anymore). Thissystem
avoids onits sine the sending transition onsumes tikets for sending while the reeiving
transitiondoesnot,and symmetrially.
In the following, we use name K for the set f0;:::;k 1g. The M-net for hannels uses
asynhronous links for data storage and values numbering; the following link symbols are use
withthefollowing meaning:
is where numbered dataare stored, under theform of ouples (v;n) where v is thevalue
and nits number(wean dedue fromthis thatmust have type setK);
nw and nr are used to remember the number for the next value to send or reeive (both
have type K);
tw andtr storetikets for sendingor reeiving (also oftype K).
The ompletesemantis for a k-bounded hannel C (1k <1)is asfollows:
Mnet(varChank ofset) = [[fI;Tg:ore ℄℄ tie f;nw;nr;tw;trg
whereIandT aresynhronousommuniationationsusedinternally.Theoreofthesemantis
an be expressedastwo onurrent iteration, one for sendsand theother forreeives:
ore = h
init send terminate i
h
wait
i
reeive wait
t i
Inthis M-net, thesending partan beonsideredasative and thereeiving partaspassive:
M-net wait
i
just waits for init to be exeuted and similarly, wait
t
waits for terminate. The
waitingM-nets an besimplyexpressedhas: wait
i
=f b
Ig:;:; and wait
t
=f b
Tg:;:;.
M-net init isomposedof asingle transitionwhihres whentherst sendtakes plae.
init=f
C!(x);Ig:f +
((x;0)); tr +
(0); tw +
(1); :::; tw +
(k 1); nw +
(1modk); nr +
(0)g:;
It stores the value, with number 0, produes all the tikets and initializes next ounters. It
also triggersM-netwait
i
thanksto asynhronization onI.(Notationtw +
(1);:::;tw +
(k 1)
isvoid whenk =1.)
Notie thatthere is no need to add aguard suh asx 2set beause the type of ensuresit
mustbethe ase.It isthe samewithsend and reeive whose denitions arequitenatural:
dend = f
C!(x)g:ftw (t); tr +
(t); nw (n); nw +
(n+1modk);
+
((x;n))g:;
+ +
Termination annot be done inone single ation beause we do not know where tikets are
and how many tokens holds (whenever it has some). This problem is solved by an iteration
wihtriggers wait
t
on starts:
terminate = h
f
C
t
;Tg:;:; ;:ftr (t); tw +
(t); ((y;n))g:;
f
C 0
t
g:ftw (0); :::; tw (k 1); nr (r); nw (w)g:;
i
(notationtw (0);:::;tw (k 1) redues to tw (0) when k =0)
Thegoalofthis iterationisto onsumeforfree eahvalueinthehannel, andforeah suh
value, one tiket is onverted. When (and only when) all thevalues are onsumed (and so, all
thetiketsare onverted),iteration mayterminate, onsumingall thetikets for sending and
thenextounters whilesynhronizingwiththeprogram ona seondtermination ation
C 0
t .
In order to model unbounded apaity, we just have to remove modulus arithmeti on the
nextounters and toforgetthe systemoftikets(justbyremoving allthelinksontwandtr):
sending isalways possible sine theapaityis unbounded and reeive is ontroled by itsnext
ounter and the availability ofdata in(atually,tikets for reeiving were useless fromthe
beginning butit wasneessaryto managethem ina oherent wayand so,on reeive also).
Inthis ase, weannotrelyon tikets toknowifthehannelisemptybutwean trustnext
ounters:whileperformingation
C 0
t
,wejusthaveto addaguard r=wwhihmeansthatthe
ount of ( )equals theount of +
( ) andsothat thehannel isempty.
Now, letusonsiderthesizeof theunfolding inthek-bounded ase.Here noplaeisdiretly
visiblesine we just gave expressions, butsine ontrol owoperatorsjustprodue plaes with
typesfg,itisenoughtofousonplaesaddedforasynhronousommuniations.Plaesfornw,
nr,twandtrhavetypeKsotheyallunfoldintok low-levelplaes.Plaes
forastypesetK
soitunfoldsinto jsetjk low-levelplaes. Sowe an statea total ofO((4+jsetj)k) whih is
aonsiderable improvement withrespetto theexponential size ink for theoldsemantis.
Asaprie forthis improvement, wenowhave twotermination ationsinsteadof onlyone.In
theterminationnet,ahannelC withtheoldsemantis ontributedanM-netfC
t
g:;:;,forour
semantis,we justhave to useinsteada sequene(fC
t
g:;:;);(fC 0
g:;:;).