spin.html 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490
  1. <html>
  2. <br><img src="-.19126690.gif"><br>
  3. <title>
  4. -
  5. </title>
  6. <body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#330088" ALINK="#FF0044">
  7. <H1>Using <small>SPIN</small>
  8. </H1>
  9. <DL><DD><I>Gerard J. Holzmann<br>
  10. gerard@plan9.bell-labs.com<br>
  11. </I></DL>
  12. <DL><DD><H4>ABSTRACT</H4>
  13. <small>SPIN</small> can be used for proving or disproving logical properties
  14. of concurrent systems.
  15. To render the proofs, a concurrent system is first
  16. modeled in a formal specification language called <small>PROMELA</small>.
  17. The language allows one to specify the behaviors
  18. of asynchronously executing
  19. processes that may interact through synchronous
  20. or asynchronous message passing, or through direct
  21. access to shared variables.
  22. <br>&#32;<br>
  23. System models specified in this way can be verified
  24. for both safety and liveness properties. The specification
  25. of general properties in linear time temporal logic is
  26. also supported.
  27. <br>&#32;<br>
  28. The first part of this manual
  29. discusses the basic features of the specification language <small>PROMELA</small>.
  30. The second part describes the verifier <small>SPIN</small>.
  31. </DL>
  32. <H4>1 The Language <small>PROMELA</small>
  33. </H4>
  34. <br>&#32;<br>
  35. <small>PROMELA</small> is short for Protocol Meta Language [Ho91].
  36. <small>PROMELA</small> is a <I>modeling</I> language, not a programming language.
  37. A formal model differs in two essential ways from an implementation.
  38. First, a model is meant to be an abstraction of a design
  39. that contains only those aspects of the design that are
  40. directly relevant to the properties one is interested in proving.
  41. Second, a formal model must contain things that are typically not part
  42. of an implementation, such as worst-case assumptions about
  43. the behavior of the environment that may interact with the
  44. system being studied, and a formal statement of relevant correctness
  45. properties. It is possible to mechanically extract abstract models
  46. from implementation level code, as discussed, for instance in [HS99].
  47. <br>&#32;<br>
  48. Verification with <small>SPIN</small> is often performed in a series of steps,
  49. with the construction of increasingly detailed models.
  50. Each model can be verified under different types of
  51. assumptions about the environment and for different
  52. types of correctness properties.
  53. If a property is not valid for the given assumptions about
  54. system behavior, the verifier can produce a counter-example
  55. that demonstrates how the property may be violated.
  56. If a property is valid, it may be possible to simplify the
  57. model based on that fact, and prove still other properties.
  58. <br>&#32;<br>
  59. Section 1.1 covers the basic building blocks of the language.
  60. Section 1.2 introduces the control flow structures.
  61. Section 1.3 explains how correctness properties are specified.
  62. Section 1.4 concludes the first part with a discussion of
  63. special predefined variables and functions that can be used to
  64. express some correctness properties.
  65. <br>&#32;<br>
  66. Up to date manual pages for <small>SPIN</small> can always be found online at:
  67. http://cm.bell-labs.com/cm/cs/what/spin/Man/
  68. <H4>1.1 Basics
  69. </H4>
  70. <br>&#32;<br>
  71. A <small>PROMELA</small> model can contain three different types of objects:
  72. <DL>
  73. <DT><DT>&#32;<DD>
  74. <DL><DD>
  75. * Processes (section 1.1.1),
  76. <br>
  77. * Variables (section 1.1.2),
  78. <br>
  79. * Message channels (section 1.1.3).
  80. </DL>
  81. </dl>
  82. <br>&#32;<br>
  83. All processes are global objects.
  84. For obvious reasons, a <small>PROMELA</small> model must contain at least one
  85. process to be meaningful.
  86. Since <small>SPIN</small> is specifically meant to prove properties of
  87. concurrent systems, a model typically contains more than
  88. one process.
  89. <br>&#32;<br>
  90. Message channels and variables, the two basic types of data objects,
  91. can be declared with either a global scope or a local scope.
  92. A data object with global scope can be referred to by all processes.
  93. A data object with a local scope can be referred to by just a
  94. single process: the process that declares and instantiates the object.
  95. As usual, all objects must be declared in the specification
  96. before they are referenced.
  97. <H4>1.1.1 Processes
  98. </H4>
  99. <br>&#32;<br>
  100. Here is a simple process that does nothing except print
  101. a line of text:
  102. <DL><DT><DD><TT><PRE>
  103. init {
  104. printf("it works\n")
  105. }
  106. </PRE></TT></DL>
  107. There are a few things to note.
  108. <TT>Init</TT>
  109. is a predefined keyword from the language.
  110. It can be used to declare and instantiate
  111. a single initial process in the model.
  112. (It is comparable to the
  113. <TT>main</TT>
  114. procedure of a C program.)
  115. The
  116. <TT>init</TT>
  117. process does not take arguments, but it can
  118. start up (instantiate) other processes that do.
  119. <TT>Printf</TT>
  120. is one of a few built-in procedures in the language.
  121. It behaves the same as the C version.
  122. Note, finally, that no semicolon follows the single
  123. <TT>printf</TT>
  124. statement in the above example.
  125. In <small>PROMELA</small>, semicolons are used as statement separators,
  126. not statement terminators. (The <small>SPIN</small> parser, however, is
  127. lenient on this issue.)
  128. <br>&#32;<br>
  129. Any process can start new processes by using another
  130. built-in procedure called
  131. <TT>run</TT>.
  132. For example,
  133. <DL><DT><DD><TT><PRE>
  134. proctype you_run(byte x)
  135. {
  136. printf("my x is: %d\n", x)
  137. }
  138. </PRE></TT></DL>
  139. <DL><DT><DD><TT><PRE>
  140. init {
  141. run you_run(1);
  142. run you_run(2)
  143. }
  144. </PRE></TT></DL>
  145. The word
  146. <TT>proctype</TT>
  147. is again a keyword that introduces the declaration
  148. of a new type of process.
  149. In this case, we have named that type
  150. <TT>you_run</TT>
  151. and declared that all instantiations of processes
  152. of this type will take one argument: a data object
  153. of type
  154. <TT>byte</TT>,
  155. that can be referred to within this process by the name
  156. <TT>x</TT>.
  157. Instances of a
  158. <TT>proctype</TT>
  159. can be created with the predefined procedure
  160. <TT>run</TT>,
  161. as shown in the example.
  162. When the
  163. <TT>run</TT>
  164. statement completes, a copy of the process
  165. has been started, and all its arguments have been
  166. initialized with the arguments provided.
  167. The process may, but need not, have performed
  168. any statement executions at this point.
  169. It is now part of the concurrent system,
  170. and its execution can be interleaved arbitrarily with
  171. those of the other, already executing processes.
  172. (More about the semantics of execution follows shortly.)
  173. <br>&#32;<br>
  174. In many cases, we are only interested in creating a
  175. single instance of each process type that is declared,
  176. and the processes require no arguments.
  177. We can define this by prefixing the keyword
  178. <TT>proctype</TT>
  179. from the process declaration with another keyword:
  180. <TT>active</TT>.
  181. Instances of all active proctypes are created when the
  182. system itself is initialized.
  183. We could, for instance, have avoided the use of
  184. <TT>init</TT>
  185. by declaring the corresponding process in the last example
  186. as follows:
  187. <DL><DT><DD><TT><PRE>
  188. active proctype main() {
  189. run you_run(1);
  190. run you_run(2)
  191. }
  192. </PRE></TT></DL>
  193. Note that there are no parameters to instantiate in this
  194. case. Had they been declared, they would default to a
  195. zero value, just like all other data objects
  196. that are not explicitly instantiated.
  197. <br>&#32;<br>
  198. Multiple copies of a process type can also be created in
  199. this way. For example:
  200. <DL><DT><DD><TT><PRE>
  201. active [4] proctype try_me() {
  202. printf("hi, i am process %d\n", _pid)
  203. }
  204. </PRE></TT></DL>
  205. creates four processes.
  206. A predefined variable
  207. <TT>_pid</TT>
  208. is assigned to each running process, and holds
  209. its unique process instantiation number.
  210. In some cases, this number is needed when a reference
  211. has to be made to a specific process.
  212. <br>&#32;<br>
  213. Summarizing: process behavior is declared in
  214. <TT>proctype</TT>
  215. definitions, and it is instantiated with either
  216. <TT>run</TT>
  217. statements or with the prefix
  218. <TT>active</TT>.
  219. Within a proctype declaration, statements are separated
  220. (not terminated) by semicolons.
  221. As we shall see in examples that follow, instead of the
  222. semicolon, one can also use the alternative separator
  223. <TT>-&gt;</TT>
  224. (arrow), wherever that may help to clarify the structure
  225. of a <small>PROMELA</small> model.
  226. <H4>Semantics of Execution
  227. </H4>
  228. <br>&#32;<br>
  229. In <small>PROMELA</small> there is no difference between a condition or
  230. expression and a statement.
  231. Fundamental to the semantics of the language is the
  232. notion of the <I>executability</I> of statements.
  233. Statements are either executable or blocked.
  234. Executability is the basic means of enforcing
  235. synchronization between the processes in a distributed system.
  236. A process can wait for an event to happen by waiting
  237. for a statement to become executable.
  238. For instance, instead of writing a busy wait loop:
  239. <DL><DT><DD><TT><PRE>
  240. while (a != b) /* not valid Promela syntax */
  241. skip; /* wait for a==b */
  242. ...
  243. </PRE></TT></DL>
  244. we achieve the same effect in <small>PROMELA</small> with the statement
  245. <DL><DT><DD><TT><PRE>
  246. (a == b);
  247. ...
  248. </PRE></TT></DL>
  249. Often we indicate that the continuation of an execution
  250. is conditional on the truth of some expression by using
  251. the alternate statement separator:
  252. <DL><DT><DD><TT><PRE>
  253. (a == b) -&gt; ...
  254. </PRE></TT></DL>
  255. Assignments and
  256. <TT>printf</TT>
  257. statements are always executable in <small>PROMELA</small>.
  258. A condition, however, can only be executed (passed) when it holds.
  259. If the condition does not hold, execution blocks until it does.
  260. There are similar rules for determining the executability
  261. of all other primitive and compound statements in the
  262. language.
  263. The semantics of each statement is defined in terms of
  264. rules for executability and effect.
  265. The rules for executability set a precondition on the state
  266. of the system in which a statement can be executed.
  267. The effect defines how a statement will alter a
  268. system state when executed.
  269. <br>&#32;<br>
  270. <small>PROMELA</small> assumes that all individual statements are executed
  271. atomically: that is, they model the smallest meaningful entities
  272. of execution in the system being studied.
  273. This means that <small>PROMELA</small> defines the standard asynchronous interleaving
  274. model of execution, where a supposed scheduler is free at
  275. each point in the execution to select any one of the processes
  276. to proceed by executing a single primitive statement.
  277. Synchronization constraints can be used to influence the
  278. interleaving patterns. It is the purpose of a concurrent system's
  279. design to constrain those patterns in such a way that no
  280. correctness requirements can be violated, and all service
  281. requirements are met. It is the purpose of the verifier
  282. either to find counter-examples to a designer's claim that this
  283. goal has been met, or to demonstrate that the claim is indeed valid.
  284. <H4>1.1.2 Variables
  285. </H4>
  286. <br>&#32;<br>
  287. The table summarizes the five basic data types used in <small>PROMELA</small>.
  288. <TT>Bit</TT>
  289. and
  290. <TT>bool</TT>
  291. are synonyms for a single bit of information.
  292. The first three types can store only unsigned quantities.
  293. The last two can hold either positive or negative values.
  294. The precise value ranges of variables of types
  295. <TT>short</TT>
  296. and
  297. <TT>int</TT>
  298. is implementation dependent, and corresponds
  299. to those of the same types in C programs
  300. that are compiled for the same hardware.
  301. The values given in the table are most common.
  302. <br><img src="-.19126691.gif"><br>
  303. <br>&#32;<br>
  304. The following example program declares a array of
  305. two elements of type
  306. <TT>bool</TT>
  307. and a scalar variable
  308. <TT>turn</TT>
  309. of the same type.
  310. Note that the example relies on the fact that
  311. <TT>_pid</TT>
  312. is either 0 or 1 here.
  313. <DL><DT><DD><TT><PRE>
  314. /*
  315. * Peterson's algorithm for enforcing
  316. * mutual exclusion between two processes
  317. * competing for access to a critical section
  318. */
  319. bool turn, want[2];
  320. active [2] proctype user()
  321. {
  322. again:
  323. want[_pid] = 1; turn = _pid;
  324. /* wait until this condition holds: */
  325. (want[1 - _pid] == 0 || turn == 1 - _pid);
  326. /* enter */
  327. critical: skip;
  328. /* leave */
  329. want[_pid] = 0;
  330. goto again
  331. }
  332. </PRE></TT></DL>
  333. In the above case, all variables are initialized to zero.
  334. The general syntax for declaring and instantiating a
  335. variable, respectively for scalar and array variables, is:
  336. <DL><DT><DD><TT><PRE>
  337. type name = expression;
  338. type name[constant] = expression
  339. </PRE></TT></DL>
  340. In the latter case, all elements of the array are initialized
  341. to the value of the expression.
  342. A missing initializer fields defaults to the value zero.
  343. As usual, multiple variables of the same type can be grouped
  344. behind a single type name, as in:
  345. <DL><DT><DD><TT><PRE>
  346. byte a, b[3], c = 4
  347. </PRE></TT></DL>
  348. In this example, the variable
  349. <TT>c</TT>
  350. is initialized to the value 4; variable
  351. <TT>a</TT>
  352. and the elements of array
  353. <TT>b</TT>
  354. are all initialized to zero.
  355. <br>&#32;<br>
  356. Variables can also be declared as structures.
  357. For example:
  358. <DL><DT><DD><TT><PRE>
  359. typedef Field {
  360. short f = 3;
  361. byte g
  362. };
  363. typedef Msg {
  364. byte a[3];
  365. int fld1;
  366. Field fld2;
  367. chan p[3];
  368. bit b
  369. };
  370. Msg foo;
  371. </PRE></TT></DL>
  372. introduces two user-defined data types, the first named
  373. <TT>Field</TT>
  374. and the second named
  375. <TT>Msg</TT>.
  376. A single variable named
  377. <TT>foo</TT>
  378. of type
  379. <TT>Msg</TT>
  380. is declared.
  381. All fields of
  382. <TT>foo</TT>
  383. that are not explicitly initialized (in the example, all fields except
  384. <TT>foo.fld2.f</TT>)
  385. are initialized to zero.
  386. References to the elements of a structure are written as:
  387. <DL><DT><DD><TT><PRE>
  388. foo.a[2] = foo.fld2.f + 12
  389. </PRE></TT></DL>
  390. A variable of a user-defined type can be passed as a single
  391. argument to a new process in
  392. <TT>run</TT>
  393. statements.
  394. For instance,
  395. <DL><DT><DD><TT><PRE>
  396. proctype me(Msg z) {
  397. z.a[2] = 12
  398. }
  399. init {
  400. Msg foo;
  401. run me(foo)
  402. }
  403. </PRE></TT></DL>
  404. <br>&#32;<br>
  405. Note that even though <small>PROMELA</small> supports only one-dimensional arrays,
  406. a two-dimensional array can be created indirectly with user-defined
  407. structures, for instance as follows:
  408. <DL><DT><DD><TT><PRE>
  409. typedef Array {
  410. byte el[4]
  411. };
  412. Array a[4];
  413. </PRE></TT></DL>
  414. This creates a data structure of 16 elements that can be
  415. referenced, for instance, as
  416. <TT>a[i].el[j]</TT>.
  417. <br>&#32;<br>
  418. As in C, the indices of an array of
  419. <TT>N</TT>
  420. elements range from 0 to
  421. <TT>N-1</TT>.
  422. <H4>Expressions
  423. </H4>
  424. <br>&#32;<br>
  425. Expressions must be side-effect free in <small>PROMELA</small>.
  426. Specifically, this means that an expression cannot
  427. contain assignments, or send and receive operations (see section 1.1.3).
  428. <DL><DT><DD><TT><PRE>
  429. c = c + 1; c = c - 1
  430. </PRE></TT></DL>
  431. and
  432. <DL><DT><DD><TT><PRE>
  433. c++; c--
  434. </PRE></TT></DL>
  435. are assignments in <small>PROMELA</small>, with the same effects.
  436. But, unlike in C,
  437. <DL><DT><DD><TT><PRE>
  438. b = c++
  439. </PRE></TT></DL>
  440. is not a valid assignment, because the right-hand side
  441. operand is not a valid expression in <small>PROMELA</small> (it is not side-effect free).
  442. <br>&#32;<br>
  443. It is also possible to write a side-effect free conditional
  444. expression, with the following syntax:
  445. <DL><DT><DD><TT><PRE>
  446. (expr1 -&gt; expr2 : expr3)
  447. </PRE></TT></DL>
  448. The parentheses around the conditional expression are required to
  449. avoid misinterpretation of the arrow.
  450. The example expression has the value of <TT>expr2</TT> when <TT>expr1</TT>
  451. evaluates to a non-zero value, and the value of <TT>expr3</TT> otherwise.
  452. <br>&#32;<br>
  453. In assignments like
  454. <DL><DT><DD><TT><PRE>
  455. variable = expression
  456. </PRE></TT></DL>
  457. the values of all operands used inside the expression are first cast to
  458. signed integers before the operands are applied.
  459. After the evaluation of the expression completes, the value produced
  460. is cast to the type of the target variable before the assignment takes place.
  461. <H4>1.1.3 Message Channels
  462. </H4>
  463. <br>&#32;<br>
  464. Message channels are used to model the transfer of data
  465. between processes.
  466. They are declared either locally or globally,
  467. for instance as follows:
  468. <DL><DT><DD><TT><PRE>
  469. chan qname = [16] of { short, byte }
  470. </PRE></TT></DL>
  471. The keyword
  472. <TT>chan</TT>
  473. introduces a channel declaration.
  474. In this case, the channel is named
  475. <TT>qname</TT>,
  476. and it is declared to be capable of storing up
  477. to 16 messages.
  478. Each message stored in the channel is declared here to
  479. consist of two fields: one of type
  480. <TT>short</TT>
  481. and one of type
  482. <TT>byte</TT>.
  483. The fields of a message can be any one of the basic types
  484. <TT>bit</TT>,
  485. <TT>bool</TT>,
  486. <TT>byte</TT>,
  487. <TT>short</TT>,
  488. <TT>int</TT>,
  489. and
  490. <TT>chan</TT>,
  491. or any user-defined type.
  492. Message fields cannot be declared as arrays.
  493. <br>&#32;<br>
  494. A message field of type
  495. <TT>chan</TT>
  496. can be used to pass a channel identifier
  497. through a channel from one process to another.
  498. <br>&#32;<br>
  499. The statement
  500. <DL><DT><DD><TT><PRE>
  501. qname!expr1,expr2
  502. </PRE></TT></DL>
  503. sends the values of expressions
  504. <TT>expr1</TT>
  505. and
  506. <TT>expr2</TT>
  507. to the channel that we just created. It appends
  508. the message field created from the values of the two
  509. expressions (and cast to the appropriate types of the
  510. message fields declared for
  511. <TT>qname</TT>)
  512. to the tail of the message buffer of 16 slots that belongs
  513. to channel
  514. <TT>qname</TT>.
  515. By default the send statement is only executable if the target
  516. channel is non-full.
  517. (This default semantics can be changed in the verifier into
  518. one where the send statement is always executable, but the
  519. message will be lost when an attempt is made to append it to
  520. a full channel.)
  521. <br>&#32;<br>
  522. The statement
  523. <DL><DT><DD><TT><PRE>
  524. qname?var1,var2
  525. </PRE></TT></DL>
  526. retrieves a message from the head of the same buffer,
  527. and stores the two expressions in variables
  528. <TT>var1</TT>
  529. and
  530. <TT>var2</TT>.
  531. <br>&#32;<br>
  532. The receive statement is executable only if the source channel
  533. is non-empty.
  534. <br>&#32;<br>
  535. If more parameters are sent per message than were declared
  536. for the message channel, the redundant parameters are lost.
  537. If fewer parameters are sent than declared,
  538. the value of the remaining parameters is undefined.
  539. Similarly, if the receive operation tries to retrieve more
  540. parameters than available, the value of the extra parameters is
  541. undefined; if it receives fewer than the number of parameters
  542. sent, the extra information is lost.
  543. <br>&#32;<br>
  544. An alternative, and equivalent, notation for the
  545. send and receive operations is to structure the
  546. message fields with parentheses, as follows:
  547. <DL><DT><DD><TT><PRE>
  548. qname!expr1(expr2,expr3)
  549. qname?var1(var2,var3)
  550. </PRE></TT></DL>
  551. In the above case, we assume that
  552. <TT>qname</TT>
  553. was declared to hold messages consisting of three fields.
  554. <P>
  555. Some or all of the arguments of the receive operation
  556. can be given as constants instead of as variables:
  557. <DL><DT><DD><TT><PRE>
  558. qname?cons1,var2,cons2
  559. </PRE></TT></DL>
  560. In this case, an extra condition on the executability of the
  561. receive operation is that the value of all message fields
  562. specified as constants match the value of the corresponding
  563. fields in the message that is to be received.
  564. </P>
  565. <br>&#32;<br>
  566. Here is an example that uses some of the mechanisms introduced
  567. so far.
  568. <DL><DT><DD><TT><PRE>
  569. proctype A(chan q1)
  570. { chan q2;
  571. q1?q2;
  572. q2!123
  573. }
  574. </PRE></TT></DL>
  575. <DL><DT><DD><TT><PRE>
  576. proctype B(chan qforb)
  577. { int x;
  578. qforb?x;
  579. printf("x = %d\n", x)
  580. }
  581. </PRE></TT></DL>
  582. <DL><DT><DD><TT><PRE>
  583. init {
  584. chan qname = [1] of { chan };
  585. chan qforb = [1] of { int };
  586. run A(qname);
  587. run B(qforb);
  588. qname!qforb
  589. }
  590. </PRE></TT></DL>
  591. The value printed by the process of type
  592. <TT>B</TT>
  593. will be
  594. <TT>123</TT>.
  595. <br>&#32;<br>
  596. A predefined function
  597. <TT>len(qname)</TT>
  598. returns the number of messages currently
  599. stored in channel
  600. <TT>qname</TT>.
  601. Two shorthands for the most common uses of this
  602. function are
  603. <TT>empty(qname)</TT>
  604. and
  605. <TT>full(qname)</TT>,
  606. with the obvious connotations.
  607. <br>&#32;<br>
  608. Since all expressions must be side-effect free,
  609. it is not valid to say:
  610. <DL><DT><DD><TT><PRE>
  611. (qname?var == 0)
  612. </PRE></TT></DL>
  613. or
  614. <DL><DT><DD><TT><PRE>
  615. (a &gt; b &amp;&amp; qname!123)
  616. </PRE></TT></DL>
  617. We could rewrite the second example (using an atomic sequence,
  618. as explained further in section 1.2.1):
  619. <DL><DT><DD><TT><PRE>
  620. atomic { (a &gt; b &amp;&amp; !full(qname)) -&gt; qname!123 }
  621. </PRE></TT></DL>
  622. The meaning of the first example is ambiguous. It could mean
  623. that we want the condition to be true if the receive operation
  624. is unexecutable. In that case, we can rewrite it without
  625. side-effects as:
  626. <DL><DT><DD><TT><PRE>
  627. empty(qname)
  628. </PRE></TT></DL>
  629. It could also mean that we want the condition
  630. to be true when the channel does contain a message with
  631. value zero.
  632. We can specify that as follows:
  633. <DL><DT><DD><TT><PRE>
  634. atomic { qname?[0] -&gt; qname?var }
  635. </PRE></TT></DL>
  636. The first statement of this atomic sequence is
  637. an expression without side-effects that
  638. evaluates to a non-zero value only if the
  639. receive operation
  640. <DL><DT><DD><TT><PRE>
  641. qname?0
  642. </PRE></TT></DL>
  643. would have been executable at that
  644. point (i.e., channel
  645. <TT>qname</TT>
  646. contains at least one message and the oldest
  647. message stored consists of one message field
  648. equal to zero).
  649. Any receive statement can be turned into
  650. a side-effect free expression by placing square
  651. brackets around the list of all message parameters.
  652. The channel contents remain undisturbed by the
  653. evaluation of such expressions.
  654. <br>&#32;<br>
  655. Note carefully, however, that in non-atomic sequences
  656. of two statements such as
  657. <DL><DT><DD><TT><PRE>
  658. !full(qname) -&gt; qname!msgtype
  659. </PRE></TT></DL>
  660. and
  661. <DL><DT><DD><TT><PRE>
  662. qname?[msgtype] -&gt; qname?msgtype
  663. </PRE></TT></DL>
  664. the second statement is not necessarily executable
  665. after the first one has been executed.
  666. There may be race conditions when access to the channels
  667. is shared between several processes.
  668. Another process can send a message to the channel
  669. just after this process determined that it was not full,
  670. or another process can steal away the
  671. message just after our process determined its presence.
  672. <br>&#32;<br>
  673. Two other types of send and receive statements are used
  674. less frequently: sorted send and random receive.
  675. A sorted send operation is written with two, instead of one,
  676. exclamation marks, as follows:
  677. <DL><DT><DD><TT><PRE>
  678. qname!!msg
  679. </PRE></TT></DL>
  680. A sorted send operation will insert a message into the channel's buffer
  681. in numerical order, instead of in FIFO order.
  682. The channel contents are scanned from the first message towards the
  683. last, and the message is inserted immediately before the first message
  684. that follows it in numerical order.
  685. To determine the numerical order, all message fields are
  686. taken into account.
  687. <br>&#32;<br>
  688. The logical counterpart of the sorted send operation
  689. is the random receive.
  690. It is written with two, instead of one, question marks:
  691. <DL><DT><DD><TT><PRE>
  692. qname??msg
  693. </PRE></TT></DL>
  694. A random receive operation is executable if it is executable for <I>any</I>
  695. message that is currently buffered in a message channel (instead of
  696. only for the first message in the channel).
  697. Normal send and receive operations can freely be combined with
  698. sorted send and random receive operations.
  699. <H4>Rendezvous Communication
  700. </H4>
  701. <br>&#32;<br>
  702. So far we have talked about asynchronous communication between processes
  703. via message channels, declared in statements such as
  704. <DL><DT><DD><TT><PRE>
  705. chan qname = [N] of { byte }
  706. </PRE></TT></DL>
  707. where
  708. <TT>N</TT>
  709. is a positive constant that defines the buffer size.
  710. A logical extension is to allow for the declaration
  711. <DL><DT><DD><TT><PRE>
  712. chan port = [0] of { byte }
  713. </PRE></TT></DL>
  714. to define a rendezvous port.
  715. The channel size is zero, that is, the channel
  716. <TT>port</TT>
  717. can pass, but cannot store, messages.
  718. Message interactions via such rendezvous ports are
  719. by definition synchronous.
  720. Consider the following example:
  721. <DL><DT><DD><TT><PRE>
  722. #define msgtype 33
  723. chan name = [0] of { byte, byte };
  724. active proctype A()
  725. { name!msgtype(124);
  726. name!msgtype(121)
  727. }
  728. </PRE></TT></DL>
  729. <DL><DT><DD><TT><PRE>
  730. active proctype B()
  731. { byte state;
  732. name?msgtype(state)
  733. }
  734. </PRE></TT></DL>
  735. Channel
  736. <TT>name</TT>
  737. is a global rendezvous port.
  738. The two processes will synchronously execute their first statement:
  739. a handshake on message
  740. <TT>msgtype</TT>
  741. and a transfer of the value 124 to local variable
  742. <TT>state</TT>.
  743. The second statement in process
  744. <TT>A</TT>
  745. will be unexecutable,
  746. because there is no matching receive operation in process
  747. <TT>B</TT>.
  748. <br>&#32;<br>
  749. If the channel
  750. <TT>name</TT>
  751. is defined with a non-zero buffer capacity,
  752. the behavior is different.
  753. If the buffer size is at least 2, the process of type
  754. <TT>A</TT>
  755. can complete its execution, before its peer even starts.
  756. If the buffer size is 1, the sequence of events is as follows.
  757. The process of type
  758. <TT>A</TT>
  759. can complete its first send action, but it blocks on the
  760. second, because the channel is now filled to capacity.
  761. The process of type
  762. <TT>B</TT>
  763. can then retrieve the first message and complete.
  764. At this point
  765. <TT>A</TT>
  766. becomes executable again and completes,
  767. leaving its last message as a residual in the channel.
  768. <br>&#32;<br>
  769. Rendezvous communication is binary: only two processes,
  770. a sender and a receiver, can be synchronized in a
  771. rendezvous handshake.
  772. <br>&#32;<br>
  773. As the example shows, symbolic constants can be defined
  774. with preprocessor macros using
  775. <TT>#define</TT>.
  776. The source text of a <small>PROMELA</small> model is translated by the standard
  777. C preprocessor.
  778. The disadvantage of defining symbolic names in this way is,
  779. however, that the <small>PROMELA</small> parser will only see the expanded text,
  780. and cannot refer to the symbolic names themselves.
  781. To prevent that, <small>PROMELA</small> also supports another way to define
  782. symbolic names, which are preserved in error reports.
  783. For instance, by including the declaration
  784. <DL><DT><DD><TT><PRE>
  785. mtype = { ack, msg, error, data };
  786. </PRE></TT></DL>
  787. at the top of a <small>PROMELA</small> model, the names provided between the
  788. curly braces are equivalent to integers of type
  789. <TT>byte</TT>,
  790. but known by their symbolic names to the <small>SPIN</small> parser and the
  791. verifiers it generates.
  792. The constant values assigned start at 1, and count up.
  793. There can be only one
  794. <TT>mtype</TT>
  795. declaration per model.
  796. <H4>1.2 Control Flow
  797. </H4>
  798. <br>&#32;<br>
  799. So far, we have seen only some of the basic statements
  800. of <small>PROMELA</small>, and the way in which they can be combined to
  801. model process behaviors.
  802. The five types of statements we have mentioned are:
  803. <TT>printf</TT>,
  804. <TT>assignment</TT>,
  805. <TT>condition</TT>,
  806. <TT>send</TT>,
  807. and
  808. <TT>receive</TT>.
  809. <br>&#32;<br>
  810. The pseudo-statement
  811. <TT>skip</TT>
  812. is syntactically and semantically equivalent to the
  813. condition
  814. <TT>(1)</TT>
  815. (i.e., to true), and is in fact quietly replaced with this
  816. expression by the lexical analyzer of <small>SPIN</small>.
  817. <br>&#32;<br>
  818. There are also five types of compound statements.
  819. <DL>
  820. <DT><DT>&#32;<DD>
  821. <DL><DD>
  822. *
  823. Atomic sequences (section 1.2.1),
  824. <br>
  825. *
  826. Deterministic steps (section 1.2.2),
  827. <br>
  828. *
  829. Selections (section 1.2.3),
  830. <br>
  831. *
  832. Repetitions (section 1.2.4),
  833. <br>
  834. *
  835. Escape sequences (section 1.2.5).
  836. </DL>
  837. </dl>
  838. <br>&#32;<br>
  839. <H4>1.2.1 Atomic Sequences
  840. </H4>
  841. <br>&#32;<br>
  842. The simplest compound statement is the
  843. <TT>atomic</TT>
  844. sequence:
  845. <DL><DT><DD><TT><PRE>
  846. atomic { /* swap the values of a and b */
  847. tmp = b;
  848. b = a;
  849. a = tmp
  850. }
  851. </PRE></TT></DL>
  852. In the example, the values of two variables
  853. <TT>a</TT>
  854. and
  855. <TT>b</TT>
  856. are swapped in a sequence of statement executions
  857. that is defined to be uninterruptable.
  858. That is, in the interleaving of process executions, no
  859. other process can execute statements from the moment that
  860. the first statement of this sequence begins to execute until
  861. the last one has completed.
  862. <br>&#32;<br>
  863. It is often useful to use
  864. <TT>atomic</TT>
  865. sequences to start a series of processes in such a
  866. way that none of them can start executing statements
  867. until all of them have been initialized:
  868. <DL><DT><DD><TT><PRE>
  869. init {
  870. atomic {
  871. run A(1,2);
  872. run B(2,3);
  873. run C(3,1)
  874. }
  875. }
  876. </PRE></TT></DL>
  877. <TT>Atomic</TT>
  878. sequences may be non-deterministic.
  879. If any statement inside an
  880. <TT>atomic</TT>
  881. sequence is found to be unexecutable, however,
  882. the atomic chain is broken, and another process can take over
  883. control.
  884. When the blocking statement becomes executable later,
  885. control can non-deterministically return to the process,
  886. and the atomic execution of the sequence resumes as if
  887. it had not been interrupted.
  888. <H4>1.2.2 Deterministic Steps
  889. </H4>
  890. <br>&#32;<br>
  891. Another way to define an indivisible sequence of actions
  892. is to use the
  893. <TT>d_step</TT>
  894. statement.
  895. In the above case, for instance, we could also have written:
  896. <DL><DT><DD><TT><PRE>
  897. d_step { /* swap the values of a and b */
  898. tmp = b;
  899. b = a;
  900. a = tmp
  901. }
  902. </PRE></TT></DL>
  903. The difference between a
  904. <TT>d_step</TT>
  905. sequence
  906. and an
  907. <TT>atomic</TT>
  908. sequence are:
  909. <UL>
  910. <LI>
  911. A
  912. <TT>d_step</TT>
  913. sequence must be completely deterministic.
  914. (If non-determinism is nonetheless encountered,
  915. it is always resolved in a fixed and deterministic
  916. way: i.e., the first true guard in selection or
  917. repetition structures is always selected.)
  918. <LI>
  919. No
  920. <TT>goto</TT>
  921. jumps into or out of a
  922. <TT>d_step</TT>
  923. sequence are permitted.
  924. <LI>
  925. The execution of a
  926. <TT>d_step</TT>
  927. sequence cannot be interrupted when a
  928. blocking statement is encountered.
  929. It is an error if any statement other than
  930. the first one in a
  931. <TT>d_step</TT>
  932. sequence is found to be unexecutable.
  933. <LI>
  934. A
  935. <TT>d_step</TT>
  936. sequence is executed as one single statement.
  937. In a way, it is a mechanism for adding new types
  938. of statements to the language.
  939. </ul>
  940. <br>&#32;<br>
  941. None of the items listed above apply to
  942. <TT>atomic</TT>
  943. sequences.
  944. This means that the keyword
  945. <TT>d_step</TT>
  946. can always be replaced with the keyword
  947. <TT>atomic</TT>,
  948. but the reverse is not true.
  949. (The main, perhaps the only, reason for using
  950. <TT>d_step</TT>
  951. sequences is to improve the efficiency of
  952. verifications.)
  953. <H4>1.2.3 Selection Structures
  954. </H4>
  955. <br>&#32;<br>
  956. A more interesting construct is the selection structure.
  957. Using the relative values of two variables
  958. <TT>a</TT>
  959. and
  960. <TT>b</TT>
  961. to choose between two options, for instance, we can write:
  962. <DL><DT><DD><TT><PRE>
  963. if
  964. :: (a != b) -&gt; option1
  965. :: (a == b) -&gt; option2
  966. fi
  967. </PRE></TT></DL>
  968. The selection structure above contains two execution sequences,
  969. each preceded by a double colon.
  970. Only one sequence from the list will be executed.
  971. A sequence can be selected only if its first statement is executable.
  972. The first statement is therefore called a <I>guard</I>.
  973. <br>&#32;<br>
  974. In the above example the guards are mutually exclusive, but they
  975. need not be.
  976. If more than one guard is executable, one of the corresponding sequences
  977. is selected nondeterministically.
  978. If all guards are unexecutable the process will block until at least
  979. one of them can be selected.
  980. There is no restriction on the type of statements that can be used
  981. as a guard: it may include sends or receives, assignments,
  982. <TT>printf</TT>,
  983. <TT>skip</TT>,
  984. etc.
  985. The rules of executability determine in each case what the semantics
  986. of the complete selection structure will be.
  987. The following example, for instance, uses receive statements
  988. as guards in a selection.
  989. <DL><DT><DD><TT><PRE>
  990. mtype = { a, b };
  991. chan ch = [1] of { byte };
  992. active proctype A()
  993. { ch!a
  994. }
  995. </PRE></TT></DL>
  996. <DL><DT><DD><TT><PRE>
  997. active proctype B()
  998. { ch!b
  999. }
  1000. </PRE></TT></DL>
  1001. <DL><DT><DD><TT><PRE>
  1002. active proctype C()
  1003. { if
  1004. :: ch?a
  1005. :: ch?b
  1006. fi
  1007. }
  1008. </PRE></TT></DL>
  1009. The example defines three processes and one channel.
  1010. The first option in the selection structure of the process
  1011. of type
  1012. <TT>C</TT>
  1013. is executable if the channel contains
  1014. a message named
  1015. <TT>a</TT>,
  1016. where
  1017. <TT>a</TT>
  1018. is a symbolic constant defined in the
  1019. <TT>mtype</TT>
  1020. declaration at the start of the program.
  1021. The second option is executable if it contains a message
  1022. <TT>b</TT>,
  1023. where, similarly,
  1024. <TT>b</TT>
  1025. is a symbolic constant.
  1026. Which message will be available depends on the unknown
  1027. relative speeds of the processes.
  1028. <br>&#32;<br>
  1029. A process of the following type will either increment
  1030. or decrement the value of variable
  1031. <TT>count</TT>
  1032. once.
  1033. <DL><DT><DD><TT><PRE>
  1034. byte count;
  1035. active proctype counter()
  1036. {
  1037. if
  1038. :: count++
  1039. :: count--
  1040. fi
  1041. }
  1042. </PRE></TT></DL>
  1043. Assignments are always executable, so the choice made
  1044. here is truly a non-deterministic one that is independent
  1045. of the initial value of the variable (zero in this case).
  1046. <H4>1.2.4 Repetition Structures
  1047. </H4>
  1048. <br>&#32;<br>
  1049. We can modify the above program as follows, to obtain
  1050. a cyclic program that randomly changes the value of
  1051. the variable up or down, by replacing the selection
  1052. structure with a repetition.
  1053. <DL><DT><DD><TT><PRE>
  1054. byte count;
  1055. active proctype counter()
  1056. {
  1057. do
  1058. :: count++
  1059. :: count--
  1060. :: (count == 0) -&gt; break
  1061. od
  1062. }
  1063. </PRE></TT></DL>
  1064. Only one option can be selected for execution at a time.
  1065. After the option completes, the execution of the structure
  1066. is repeated.
  1067. The normal way to terminate the repetition structure is
  1068. with a
  1069. <TT>break</TT>
  1070. statement.
  1071. In the example, the loop can be
  1072. broken only when the count reaches zero.
  1073. Note, however, that it need not terminate since the other
  1074. two options remain executable.
  1075. To force termination we could modify the program as follows.
  1076. <DL><DT><DD><TT><PRE>
  1077. active proctype counter()
  1078. {
  1079. do
  1080. :: (count != 0) -&gt;
  1081. if
  1082. :: count++
  1083. :: count--
  1084. fi
  1085. :: (count == 0) -&gt; break
  1086. od
  1087. }
  1088. </PRE></TT></DL>
  1089. A special type of statement that is useful in selection
  1090. and repetition structures is the
  1091. <TT>else</TT>
  1092. statement.
  1093. An
  1094. <TT>else</TT>
  1095. statement becomes executable only if no other statement
  1096. within the same process, at the same control-flow point,
  1097. is executable.
  1098. We could try to use it in two places in the above example:
  1099. <DL><DT><DD><TT><PRE>
  1100. active proctype counter()
  1101. {
  1102. do
  1103. :: (count != 0) -&gt;
  1104. if
  1105. :: count++
  1106. :: count--
  1107. :: else
  1108. fi
  1109. :: else -&gt; break
  1110. od
  1111. }
  1112. </PRE></TT></DL>
  1113. The first
  1114. <TT>else</TT>,
  1115. inside the nested selection structure, can never become
  1116. executable though, and is therefore redundant (both alternative
  1117. guards of the selection are assignments, which are always
  1118. executable).
  1119. The second usage of the
  1120. <TT>else</TT>,
  1121. however, becomes executable exactly when
  1122. <TT>!(count != 0)</TT>
  1123. or
  1124. <TT>(count == 0)</TT>,
  1125. and is therefore equivalent to the latter to break from the loop.
  1126. <br>&#32;<br>
  1127. There is also an alternative way to exit the do-loop, without
  1128. using a
  1129. <TT>break</TT>
  1130. statement: the infamous
  1131. <TT>goto</TT>.
  1132. This is illustrated in the following implementation of
  1133. Euclid's algorithm for finding the greatest common divisor
  1134. of two non-zero, positive numbers:
  1135. <DL><DT><DD><TT><PRE>
  1136. proctype Euclid(int x, y)
  1137. {
  1138. do
  1139. :: (x &gt; y) -&gt; x = x - y
  1140. :: (x &lt; y) -&gt; y = y - x
  1141. :: (x == y) -&gt; goto done
  1142. od;
  1143. done:
  1144. skip
  1145. }
  1146. </PRE></TT></DL>
  1147. <DL><DT><DD><TT><PRE>
  1148. init { run Euclid(36, 12) }
  1149. </PRE></TT></DL>
  1150. The
  1151. <TT>goto</TT>
  1152. in this example jumps to a label named
  1153. <TT>done</TT>.
  1154. Since a label can only appear before a statement,
  1155. we have added the dummy statement
  1156. <TT>skip</TT>.
  1157. Like a
  1158. <TT>skip</TT>,
  1159. a
  1160. <TT>goto</TT>
  1161. statement is always executable and has no other
  1162. effect than to change the control-flow point
  1163. of the process that executes it.
  1164. <br>&#32;<br>
  1165. As a final example, consider the following implementation of
  1166. a Dijkstra semaphore, which is implemented with the help of
  1167. a synchronous channel.
  1168. <DL><DT><DD><TT><PRE>
  1169. #define p 0
  1170. #define v 1
  1171. chan sema = [0] of { bit };
  1172. </PRE></TT></DL>
  1173. <DL><DT><DD><TT><PRE>
  1174. active proctype Dijkstra()
  1175. { byte count = 1;
  1176. do
  1177. :: (count == 1) -&gt;
  1178. sema!p; count = 0
  1179. :: (count == 0) -&gt;
  1180. sema?v; count = 1
  1181. od
  1182. }
  1183. </PRE></TT></DL>
  1184. <DL><DT><DD><TT><PRE>
  1185. active [3] proctype user()
  1186. { do
  1187. :: sema?p;
  1188. /* critical section */
  1189. sema!v;
  1190. /* non-critical section */
  1191. od
  1192. }
  1193. </PRE></TT></DL>
  1194. The semaphore guarantees that only one of the three user processes
  1195. can enter its critical section at a time.
  1196. It does not necessarily prevent the monopolization of
  1197. the access to the critical section by one of the processes.
  1198. <br>&#32;<br>
  1199. <small>PROMELA</small> does not have a mechanism for defining functions or
  1200. procedures. Where necessary, though, these may be
  1201. modeled with the help of additional processes.
  1202. The return value of a function, for instance, can be passed
  1203. back to the calling process via global variables or messages.
  1204. The following program illustrates this by recursively
  1205. calculating the factorial of a number
  1206. <TT>n</TT>.
  1207. <DL><DT><DD><TT><PRE>
  1208. proctype fact(int n; chan p)
  1209. { chan child = [1] of { int };
  1210. int result;
  1211. if
  1212. :: (n &lt;= 1) -&gt; p!1
  1213. :: (n &gt;= 2) -&gt;
  1214. run fact(n-1, child);
  1215. child?result;
  1216. p!n*result
  1217. fi
  1218. }
  1219. </PRE></TT></DL>
  1220. <DL><DT><DD><TT><PRE>
  1221. init
  1222. { chan child = [1] of { int };
  1223. int result;
  1224. run fact(7, child);
  1225. child?result;
  1226. printf("result: %d\n", result)
  1227. }
  1228. </PRE></TT></DL>
  1229. Each process creates a private channel and uses it
  1230. to communicate with its direct descendant.
  1231. There are no input statements in <small>PROMELA</small>.
  1232. The reason is that models must always be complete to
  1233. allow for logical verifications, and input statements
  1234. would leave at least the source of some information unspecified.
  1235. A way to read input
  1236. would presuppose a source of information that is not
  1237. part of the model.
  1238. <br>&#32;<br>
  1239. We have already discussed a few special types of statement:
  1240. <TT>skip</TT>,
  1241. <TT>break</TT>,
  1242. and
  1243. <TT>else</TT>.
  1244. Another statement in this class is the
  1245. <TT>timeout</TT>.
  1246. The
  1247. <TT>timeout</TT>
  1248. is comparable to a system level
  1249. <TT>else</TT>
  1250. statement: it becomes executable if and only if no other
  1251. statement in any of the processes is executable.
  1252. <TT>Timeout</TT>
  1253. is a modeling feature that provides for an escape from a
  1254. potential deadlock state.
  1255. The
  1256. <TT>timeout</TT>
  1257. takes no parameters, because the types of properties we
  1258. would like to prove for <small>PROMELA</small> models must be proven independent
  1259. of all absolute and relative timing considerations.
  1260. In particular, the relative speeds of processes can never be
  1261. known with certainty in an asynchronous system.
  1262. <H4>1.2.5 Escape Sequences
  1263. </H4>
  1264. <br>&#32;<br>
  1265. The last type of compound structure to be discussed is the
  1266. <TT>unless</TT>
  1267. statement.
  1268. It is used as follows:
  1269. <DL><DT><DD><TT><PRE>
  1270. { P } unless { E }
  1271. </PRE></TT></DL>
  1272. where the letters
  1273. <TT>P</TT>
  1274. and
  1275. <TT>E</TT>
  1276. represent arbitrary <small>PROMELA</small> fragments.
  1277. Execution of the
  1278. <TT>unless</TT>
  1279. statement begins with the execution of statements from
  1280. <TT>P</TT>.
  1281. Before each statement execution in
  1282. <TT>P</TT>
  1283. the executability of the first statement of
  1284. <TT>E</TT>
  1285. is checked, using the normal <small>PROMELA</small> semantics of executability.
  1286. Execution of statements from
  1287. <TT>P</TT>
  1288. proceeds only while the first statement of
  1289. <TT>E</TT>
  1290. remains unexecutable.
  1291. The first time that this `guard of the escape sequence'
  1292. is found to be executable, control changes to it,
  1293. and execution continues as defined for
  1294. <TT>E</TT>.
  1295. Individual statement executions remain indivisible,
  1296. so control can only change from inside
  1297. <TT>P</TT>
  1298. to the start of
  1299. <TT>E</TT>
  1300. in between individual statement executions.
  1301. If the guard of the escape sequence
  1302. does not become executable during the
  1303. execution of
  1304. <TT>P</TT>,
  1305. then it is skipped entirely when
  1306. <TT>P</TT>
  1307. terminates.
  1308. <br>&#32;<br>
  1309. An example of the use of escape sequences is:
  1310. <DL><DT><DD><TT><PRE>
  1311. A;
  1312. do
  1313. :: b1 -&gt; B1
  1314. :: b2 -&gt; B2
  1315. ...
  1316. od
  1317. unless { c -&gt; C };
  1318. D
  1319. </PRE></TT></DL>
  1320. As shown in the example, the curly braces around the main sequence
  1321. (or the escape sequence) can be deleted if there can be no confusion
  1322. about which statements belong to those sequences.
  1323. In the example, condition
  1324. <TT>c</TT>
  1325. acts as a watchdog on the repetition construct from the main sequence.
  1326. Note that this is not necessarily equivalent to the construct
  1327. <DL><DT><DD><TT><PRE>
  1328. A;
  1329. do
  1330. :: b1 -&gt; B1
  1331. :: b2 -&gt; B2
  1332. ...
  1333. :: c -&gt; break
  1334. od;
  1335. C; D
  1336. </PRE></TT></DL>
  1337. if
  1338. <TT>B1</TT>
  1339. or
  1340. <TT>B2</TT>
  1341. are non-empty.
  1342. In the first version of the example, execution of the iteration can
  1343. be interrupted at <I>any</I> point inside each option sequence.
  1344. In the second version, execution can only be interrupted at the
  1345. start of the option sequences.
  1346. <H4>1.3 Correctness Properties
  1347. </H4>
  1348. <br>&#32;<br>
  1349. There are three ways to express correctness properties in <small>PROMELA</small>,
  1350. using:
  1351. <DL>
  1352. <DT><DT>&#32;<DD>
  1353. <DL><DD>
  1354. <br>
  1355. *
  1356. Assertions (section 1.3.1),
  1357. <br>
  1358. *
  1359. Special labels (section 1.3.2),
  1360. <br>
  1361. *
  1362. <TT>Never</TT>
  1363. claims (section 1.3.3).
  1364. </DL>
  1365. </dl>
  1366. <br>&#32;<br>
  1367. <H4>1.3.1 Assertions
  1368. </H4>
  1369. <br>&#32;<br>
  1370. Statements of the form
  1371. <DL><DT><DD><TT><PRE>
  1372. assert(expression)
  1373. </PRE></TT></DL>
  1374. are always executable.
  1375. If the expression evaluates to a non-zero value (i.e., the
  1376. corresponding condition holds), the statement has no effect
  1377. when executed.
  1378. The correctness property expressed, though, is that it is
  1379. impossible for the expression to evaluate to zero (i.e., for
  1380. the condition to be false).
  1381. A failing assertion will cause execution to be aborted.
  1382. <H4>1.3.2 Special Labels
  1383. </H4>
  1384. <br>&#32;<br>
  1385. Labels in a <small>PROMELA</small> specification ordinarily serve as
  1386. targets for unconditional
  1387. <TT>goto</TT>
  1388. jumps, as usual.
  1389. There are, however, also three types of labels that
  1390. have a special meaning to the verifier.
  1391. We discuss them in the next three subsections.
  1392. <H4>1.3.2.1 End-State Labels
  1393. </H4>
  1394. <br>&#32;<br>
  1395. When a <small>PROMELA</small> model is checked for reachable deadlock states
  1396. by the verifier, it must be able to distinguish valid <I>end state</I>s
  1397. from invalid ones.
  1398. By default, the only valid end states are those in which
  1399. every <small>PROMELA</small> process that was instantiated has reached the end of
  1400. its code.
  1401. Not all <small>PROMELA</small> processes, however, are meant to reach the
  1402. end of their code.
  1403. Some may very well linger in a known wait
  1404. state, or they may sit patiently in a loop
  1405. ready to spring into action when new input arrives.
  1406. <br>&#32;<br>
  1407. To make it clear to the verifier that these alternate end states
  1408. are also valid, we can define special end-state labels.
  1409. We can do so, for instance, in the process type
  1410. <TT>Dijkstra</TT>,
  1411. from an earlier example:
  1412. <DL><DT><DD><TT><PRE>
  1413. proctype Dijkstra()
  1414. { byte count = 1;
  1415. end: do
  1416. :: (count == 1) -&gt;
  1417. sema!p; count = 0
  1418. :: (count == 0) -&gt;
  1419. sema?v; count = 1
  1420. od
  1421. }
  1422. </PRE></TT></DL>
  1423. The label
  1424. <TT>end</TT>
  1425. defines that it is not an error if, at the end of an
  1426. execution sequence, a process of this type
  1427. has not reached its closing curly brace, but waits at the label.
  1428. Of course, such a state could still be part of a deadlock state, but
  1429. if so, it is not caused by this particular process.
  1430. <br>&#32;<br>
  1431. There may be more than one end-state label per <small>PROMELA</small> model.
  1432. If so, all labels that occur within the same process body must
  1433. be unique.
  1434. The rule is that every label name with the prefix
  1435. <TT>end</TT>
  1436. is taken to be an end-state label.
  1437. <H4>1.3.2.2 Progress-State Labels
  1438. </H4>
  1439. <br>&#32;<br>
  1440. In the same spirit, <small>PROMELA</small> also allows for the definition of
  1441. <TT>progress</TT>
  1442. labels.
  1443. Passing a progress label during an execution is interpreted
  1444. as a good thing: the process is not just idling while
  1445. waiting for things to happen elsewhere, but is making
  1446. effective progress in its execution.
  1447. The implicit correctness property expressed here is that any
  1448. infinite execution cycle allowed by the model that does not
  1449. pass through at least one of these progress labels is a
  1450. potential starvation loop.
  1451. In the
  1452. <TT>Dijkstra</TT>
  1453. example, for instance, we can label the
  1454. successful passing of a semaphore test as progress and
  1455. ask a verifier to make sure that there is no cycle elsewhere
  1456. in the system.
  1457. <DL><DT><DD><TT><PRE>
  1458. proctype Dijkstra()
  1459. { byte count = 1;
  1460. end: do
  1461. :: (count == 1) -&gt;
  1462. progress: sema!p; count = 0
  1463. :: (count == 0) -&gt;
  1464. sema?v; count = 1
  1465. od
  1466. }
  1467. </PRE></TT></DL>
  1468. If more than one state carries a progress label,
  1469. variations with a common prefix are again valid.
  1470. <H4>1.3.2.3 Accept-State Labels
  1471. </H4>
  1472. <br>&#32;<br>
  1473. The last type of label, the accept-state label, is used
  1474. primarily in combination with
  1475. <TT>never</TT>
  1476. claims.
  1477. Briefly, by labeling a state with any label starting
  1478. with the prefix
  1479. <TT>accept</TT>
  1480. we can ask the verifier to find all cycles that <I>do</I>
  1481. pass through at least one of those labels.
  1482. The implicit correctness claim is that this cannot happen.
  1483. The primary place where accept labels are used is inside
  1484. <TT>never</TT>
  1485. claims.
  1486. We discuss
  1487. <TT>never</TT>
  1488. claims next.
  1489. <H4>1.3.3 Never Claims
  1490. </H4>
  1491. <br>&#32;<br>
  1492. Up to this point we have talked about the specification
  1493. of correctness criteria with assertions
  1494. and with three special types of labels.
  1495. Powerful types of correctness criteria can already
  1496. be expressed with these tools, yet so far our only option is
  1497. to add them to individual
  1498. <TT>proctype</TT>
  1499. declarations.
  1500. We can, for instance, express the claim ``every system state
  1501. in which property
  1502. <TT>P</TT>
  1503. is true eventually leads to a system state in which property
  1504. <TT>Q</TT>
  1505. is true,'' with an extra monitor process, such as:
  1506. <DL><DT><DD><TT><PRE>
  1507. active proctype monitor()
  1508. {
  1509. progress:
  1510. do
  1511. :: P -&gt; Q
  1512. od
  1513. }
  1514. </PRE></TT></DL>
  1515. If we require that property
  1516. <TT>P</TT>
  1517. must <I>remain</I> true while we are waiting
  1518. <TT>Q</TT>
  1519. to become true, we can try to change this to:
  1520. <DL><DT><DD><TT><PRE>
  1521. active proctype monitor()
  1522. {
  1523. progress:
  1524. do
  1525. :: P -&gt; assert(P || Q)
  1526. od
  1527. }
  1528. </PRE></TT></DL>
  1529. but this does not quite do the job.
  1530. Note that we cannot make any assumptions about the
  1531. relative execution speeds of processes in a <small>PROMELA</small> model.
  1532. This means that if in the remainder of the system the
  1533. property
  1534. <TT>P</TT>
  1535. becomes true, we can move to the state just before the
  1536. <TT>assert</TT>,
  1537. and wait there for an unknown amount of time (anything between
  1538. a zero delay and an infinite delay is possible here, since
  1539. no other synchronizations apply).
  1540. If
  1541. <TT>Q</TT>
  1542. becomes true, we may pass the assertion, but we need not
  1543. do so.
  1544. Even if
  1545. <TT>P</TT>
  1546. becomes false only <I>after</I>
  1547. <TT>Q</TT>
  1548. has become true, we may still fail the assertion,
  1549. as long as there exists some later state where neither
  1550. <TT>P</TT>
  1551. nor
  1552. <TT>Q</TT>
  1553. is true.
  1554. This is clearly unsatisfactory, and we need another mechanism
  1555. to express these important types of liveness properties.
  1556. <H4>The Connection with Temporal Logic
  1557. </H4>
  1558. <br>&#32;<br>
  1559. A general way to express system properties of the type we
  1560. have just discussed is to use linear time temporal logic (LTL)
  1561. formulae.
  1562. Every <small>PROMELA</small> expression is automatically also a valid LTL formula.
  1563. An LTL formula can also contain the unary temporal operators &#164;
  1564. (pronounced always), &#186; (pronounced eventually), and
  1565. two binary temporal operators
  1566. <TT>U</TT>
  1567. (pronounced weak until) and
  1568. <B><I>U</I></B>
  1569. (pronounced strong until).
  1570. <br>&#32;<br>
  1571. Where the value of a <small>PROMELA</small> expression without temporal operators can be
  1572. defined uniquely for individual system states, without further context,
  1573. the truth value of an LTL formula is defined for sequences of states:
  1574. specifically, it is defined for the first state of a given infinite
  1575. sequence of system states (a trace).
  1576. Given, for instance, the sequence of system states:
  1577. <DL><DT><DD><TT><PRE>
  1578. s0;s1;s2;...
  1579. </PRE></TT></DL>
  1580. the LTL formula
  1581. <TT>pUq</TT>,
  1582. with
  1583. <TT>p</TT>
  1584. and
  1585. <TT>q</TT>
  1586. standard <small>PROMELA</small> expressions, is true for
  1587. <TT>s0</TT>
  1588. either if
  1589. <TT>q</TT>
  1590. is true in
  1591. <TT>s0</TT>,
  1592. or if
  1593. <TT>p</TT>
  1594. is true in
  1595. <TT>s0</TT>
  1596. and
  1597. <TT>pUq</TT>
  1598. holds for the remainder of the sequence after
  1599. <TT>s0</TT>.
  1600. <br>&#32;<br>
  1601. Informally,
  1602. <TT>pUq</TT>
  1603. says that
  1604. <TT>p</TT>
  1605. is required to hold at least until
  1606. <TT>q</TT>
  1607. becomes true.
  1608. If, instead, we would write <TT>p</TT><B><I>U</I></B><TT>q</TT>,
  1609. then we also require that there exists at least
  1610. one state in the sequence where
  1611. <TT>q</TT>
  1612. does indeed become true.
  1613. <br>&#32;<br>
  1614. The temporal operators &#164; and &#186;
  1615. can be defined in terms of the strong until operator
  1616. <B><I>U</I></B>,
  1617. as follows.
  1618. <DL><DT><DD><TT><PRE>
  1619. &#164; p = !&#186; !p = !(true <B><I>U</I></B><TT> !p)
  1620. </PRE></TT></DL>
  1621. Informally, &#164;
  1622. </TT><TT>p</TT><TT>
  1623. says that property
  1624. </TT><TT>p</TT><TT>
  1625. must hold in all states of a trace, and &#186;
  1626. </TT><TT>p</TT><TT>
  1627. says that
  1628. </TT><TT>p</TT><TT>
  1629. holds in at least one state of the trace.
  1630. </TT><br>&#32;<br>
  1631. To express our original example requirement: ``every system state
  1632. in which property
  1633. <TT>P</TT>
  1634. is true eventually leads to a system state in which property
  1635. <TT>Q</TT>
  1636. is true,''
  1637. we can write the LTL formula:
  1638. <DL><DT><DD><TT><PRE>
  1639. &#164; (P -&gt; &#186; Q)
  1640. </PRE></TT></DL>
  1641. where the logical implication symbol
  1642. <TT>-&gt;</TT>
  1643. is defined in the usual way as
  1644. <DL><DT><DD><TT><PRE>
  1645. P =&gt; Q means !P || Q
  1646. </PRE></TT></DL>
  1647. <H4>Mapping LTL Formulae onto Never Claims
  1648. </H4>
  1649. <br>&#32;<br>
  1650. <small>PROMELA</small> does not include syntax for specifying LTL formulae
  1651. directly, but it relies on the fact that every such
  1652. formula can be translated into a special type of
  1653. automaton, known as a B&uuml;chi automaton.
  1654. In the syntax of <small>PROMELA</small> this automaton is called a
  1655. <TT>never</TT>
  1656. claim.
  1657. If you don't care too much about the details of
  1658. <TT>never</TT>
  1659. claims, you can skip the remainder of this section and
  1660. simple remember that <small>SPIN</small> can convert any LTL formula
  1661. automatically into the proper never claim syntax with
  1662. the command:
  1663. <DL><DT><DD><TT><PRE>
  1664. spin -f "...formula..."
  1665. </PRE></TT></DL>
  1666. Here are the details.
  1667. The syntax of a never claim is:
  1668. <DL><DT><DD><TT><PRE>
  1669. never {
  1670. ...
  1671. }
  1672. </PRE></TT></DL>
  1673. where the dots can contain any <small>PROMELA</small> fragment, including
  1674. arbitrary repetition, selection, unless constructs,
  1675. jumps, etc.
  1676. <br>&#32;<br>
  1677. There is an important difference in semantics between a
  1678. <TT>proctype</TT>
  1679. declaration and a
  1680. <TT>never</TT>
  1681. claim.
  1682. Every statement inside a
  1683. <TT>never</TT>
  1684. claim is interpreted as a proposition, i.e., a condition.
  1685. A
  1686. <TT>never</TT>
  1687. claim should therefore only contain expressions and never
  1688. statements that can have side-effects (assignments, sends or
  1689. receives, run-statements, etc.)
  1690. <br>&#32;<br>
  1691. <TT>Never</TT>
  1692. claims are used to express behaviors that are considered
  1693. undesirable or illegal.
  1694. We say that a
  1695. <TT>never</TT>
  1696. claim is `matched' if the undesirable behavior can be realized,
  1697. contrary to the claim, and thus the correctness requirement violated.
  1698. The claims are evaluated over system executions, that is, the
  1699. propositions that are listed in the claim are evaluated over the
  1700. traces from the remainder of the system.
  1701. The claim, therefore, should not alter that behavior: it merely
  1702. monitors it.
  1703. Every time that the system reaches a new state, by asynchronously
  1704. executing statements from the model, the claim will evaluate the
  1705. appropriate propositions to determine if a counter-example can
  1706. be constructed to the implicit LTL formula that is specified.
  1707. <br>&#32;<br>
  1708. Since LTL formulae are only defined for infinite executions,
  1709. the behavior of a
  1710. <TT>never</TT>
  1711. claim can only be matched by an infinite system execution.
  1712. This by itself would restrict us to the use of progress labels
  1713. and accept labels as the only means we have discussed so far
  1714. for expressing properties of infinite behaviors.
  1715. To conform to standard omega automata theory, the behaviors of
  1716. <TT>never</TT>
  1717. claims are expressed exclusively with
  1718. <TT>accept</TT>
  1719. labels (never with
  1720. <TT>progress</TT>
  1721. labels).
  1722. To match a claim, therefore, an infinite sequence of true propositions
  1723. must exist, at least one of which is labeled with an
  1724. <TT>accept</TT>
  1725. label (inside the never claim).
  1726. <br>&#32;<br>
  1727. Since <small>PROMELA</small> models can also express terminating system behaviors,
  1728. we have to define the semantics of the
  1729. <TT>never</TT>
  1730. claims also for those behaviors.
  1731. To facilitate this, it is defined that a
  1732. <TT>never</TT>
  1733. claim can also be matched when it reaches its closing curly brace
  1734. (i.e., when it appears to terminate).
  1735. This semantics is based on what is usually referred to as a `stuttering
  1736. semantics.'
  1737. With stuttering semantics, any terminating execution can be extended
  1738. into an equivalent infinite execution (for the purposes of evaluating
  1739. LTL properties) by repeating (stuttering) the final state infinitely often.
  1740. As a syntactical convenience, the final state of a
  1741. <TT>never</TT>
  1742. claim is defined to be accepting, i.e., it could be replaced with
  1743. the explicit repetition construct:
  1744. <DL><DT><DD><TT><PRE>
  1745. accept: do :: skip od
  1746. </PRE></TT></DL>
  1747. Every process behavior, similarly, is (for the purposes of evaluating the
  1748. <TT>never</TT>
  1749. claims) thought to be extended with a dummy self-loop on all final states:
  1750. <DL><DT><DD><TT><PRE>
  1751. do :: skip od
  1752. </PRE></TT></DL>
  1753. (Note the
  1754. <TT>accept</TT>
  1755. labels only occur in the
  1756. <TT>never</TT>
  1757. claim, not in the system.)
  1758. <H4>The Semantics of a Never Claim
  1759. </H4>
  1760. <br>&#32;<br>
  1761. <TT>Never</TT>
  1762. claims are probably the hardest part of the language to understand,
  1763. so it is worth spending a few extra words on them.
  1764. On an initial reading, feel free to skip the remainder of this
  1765. section.
  1766. <br>&#32;<br>
  1767. The difference between a
  1768. <TT>never</TT>
  1769. claim and the remainder of a <small>PROMELA</small> system can be explained
  1770. as follows.
  1771. A <small>PROMELA</small> model defines an asynchronous interleaving product of the
  1772. behaviors of individual processes.
  1773. Given an arbitrary system state, its successor states are
  1774. conceptually obtained in two steps.
  1775. In a first step, all the executable statements in the
  1776. individual processes are identified.
  1777. In a second step, each one of these statements is executed,
  1778. each one producing one potential successor for the current state.
  1779. The complete system behavior is thus defined recursively and
  1780. represents all possible interleavings of the individual process behaviors.
  1781. It is this asynchronous product machine that we call the `global
  1782. system behavior'.
  1783. <br>&#32;<br>
  1784. The addition of a
  1785. <TT>never</TT>
  1786. claim defines a <I>synchronous</I> product of the global system behavior
  1787. with the behavior expressed in the claim.
  1788. This synchronous product can be thought of as the construction of a
  1789. new global state machine, in which every state is defined as a pair
  1790. <TT>(s,n)</TT>
  1791. with
  1792. <TT>s</TT>
  1793. a state from the global system (the asynchronous product of processes), and
  1794. <TT>n</TT>
  1795. a state from the claim.
  1796. Every transition in the new global machine is similarly defined by a pair
  1797. of transitions, with the first element a statement from the system, and the
  1798. second a proposition from the claim.
  1799. In other words, every transition in this final synchronous product is
  1800. defined as a joint transition of the system and the claim.
  1801. Of course, that transition can only occur if the proposition from the
  1802. second half of the transition pair evaluates to true in the current state
  1803. of the system (the first half of the state pair).
  1804. <H4>Examples
  1805. </H4>
  1806. <br>&#32;<br>
  1807. To manually translate an LTL formula into a
  1808. <TT>never</TT>
  1809. claim (e.g. foregoing the builtin translation that <small>SPIN</small>
  1810. offers), we must carefully consider whether the
  1811. formula expresses a positive or a negative property.
  1812. A positive property expresses a good behavior that we
  1813. would like our system to have.
  1814. A negative property expresses a bad behavior that we
  1815. claim the system does not have.
  1816. A
  1817. <TT>never</TT>
  1818. claim can express only negative claims, not positive ones.
  1819. Fortunately, the two are exchangeable: if we want to express
  1820. that a good behavior is unavoidable, we can formalize all
  1821. ways in which the good behavior could be violated, and express
  1822. that in the
  1823. <TT>never</TT>
  1824. claim.
  1825. <br>&#32;<br>
  1826. Suppose that the LTL formula &#186;&#164;
  1827. <TT>p</TT>,
  1828. with
  1829. <TT>p</TT>
  1830. a <small>PROMELA</small> expression, expresses a negative claim
  1831. (i.e., it is considered a correctness violation if
  1832. there exists any execution sequence in which
  1833. <TT>p</TT>
  1834. can eventually remain true infinitely long).
  1835. This can be written in a
  1836. <TT>never</TT>
  1837. claim as:
  1838. <DL><DT><DD><TT><PRE>
  1839. never { /* &lt;&gt;[]p */
  1840. do
  1841. :: skip /* after an arbitrarily long prefix */
  1842. :: p -&gt; break /* p becomes true */
  1843. od;
  1844. accept: do
  1845. :: p /* and remains true forever after */
  1846. od
  1847. }
  1848. </PRE></TT></DL>
  1849. Note that in this case the claim does not terminate, and
  1850. also does not necessarily match all system behaviors.
  1851. It is sufficient if it precisely captures all violations
  1852. of our correctness requirement, and no more.
  1853. <br>&#32;<br>
  1854. If the LTL formula expressed a positive property, we first
  1855. have to invert it to the corresponding negative property
  1856. <TT>&#186;!p</TT>
  1857. and translate that into a
  1858. <TT>never</TT>
  1859. claim.
  1860. The requirement now says that it is a violation if
  1861. <TT>p</TT>
  1862. does not hold infinitely long.
  1863. <DL><DT><DD><TT><PRE>
  1864. never { /* &lt;&gt;!p*/
  1865. do
  1866. :: skip
  1867. :: !p -&gt; break
  1868. od
  1869. }
  1870. </PRE></TT></DL>
  1871. We have used the implicit match of a claim upon reaching the
  1872. closing terminating brace.
  1873. Since the first violation of the property suffices to disprove
  1874. it, we could also have written:
  1875. <DL><DT><DD><TT><PRE>
  1876. never { /* &lt;&gt;!p*/
  1877. do
  1878. :: p
  1879. :: !p -&gt; break
  1880. od
  1881. }
  1882. </PRE></TT></DL>
  1883. or, if we abandon the connection with LTL for a moment,
  1884. even more tersely as:
  1885. <DL><DT><DD><TT><PRE>
  1886. never { do :: assert(p) od }
  1887. </PRE></TT></DL>
  1888. Suppose we wish to express that it is a violation of our
  1889. correctness requirements if there exists any execution in
  1890. the system where
  1891. <TT>&#164; (p -&gt; &#186; q)</TT>
  1892. is violated (i.e., the negation of this formula is satisfied).
  1893. The following
  1894. <TT>never</TT>
  1895. claim expresses that property:
  1896. <DL><DT><DD><TT><PRE>
  1897. never {
  1898. do
  1899. :: skip
  1900. :: p &amp;&amp; !q -&gt; break
  1901. od;
  1902. accept:
  1903. do
  1904. :: !q
  1905. od
  1906. }
  1907. </PRE></TT></DL>
  1908. Note that using
  1909. <TT>(!p || q)</TT>
  1910. instead of
  1911. <TT>skip</TT>
  1912. in the first repetition construct would imply a check for just
  1913. the first occurrence of proposition
  1914. <TT>p</TT>
  1915. becoming true in the execution sequence, while
  1916. <TT>q</TT>
  1917. is false.
  1918. The above formalization checks for all occurrences, anywhere in a trace.
  1919. <br>&#32;<br>
  1920. Finally, consider a formalization of the LTL property
  1921. <TT>&#164; (p -&gt; (q U r))</TT>.
  1922. The corresponding claim is:
  1923. <DL><DT><DD><TT><PRE>
  1924. never {
  1925. do
  1926. :: skip /* to match any occurrence */
  1927. :: p &amp;&amp; q &amp;&amp; !r -&gt; break
  1928. :: p &amp;&amp; !q &amp;&amp; !r -&gt; goto error
  1929. od;
  1930. do
  1931. :: q &amp;&amp; !r
  1932. :: !q &amp;&amp; !r -&gt; break
  1933. od;
  1934. error: skip
  1935. }
  1936. </PRE></TT></DL>
  1937. Note again the use of
  1938. <TT>skip</TT>
  1939. instead of
  1940. <TT>(!p || r)</TT>
  1941. to avoid matching just the first occurrence of
  1942. <TT>(p && !r)</TT>
  1943. in a trace.
  1944. <H4>1.4 Predefined Variables and Functions
  1945. </H4>
  1946. <br>&#32;<br>
  1947. The following predefined variables and functions
  1948. can be especially useful in
  1949. <TT>never</TT>
  1950. claims.
  1951. <br>&#32;<br>
  1952. The predefined variables are:
  1953. <TT>_pid</TT>
  1954. and
  1955. <TT>_last</TT>.
  1956. <br>&#32;<br>
  1957. <TT>_pid</TT>
  1958. is a predefined local variable in each process
  1959. that holds the unique instantiation number for
  1960. that process.
  1961. It is always a non-negative number.
  1962. <br>&#32;<br>
  1963. <TT>_last</TT>
  1964. is a predefined global variable that always holds the
  1965. instantiation number of the process that performed the last
  1966. step in the current execution sequence.
  1967. Its value is not part of the system state unless it is
  1968. explicitly used in a specification.
  1969. <DL><DT><DD><TT><PRE>
  1970. never {
  1971. /* it is not possible for the process with pid=1
  1972. * to execute precisely every other step forever
  1973. */
  1974. accept:
  1975. do
  1976. :: _last != 1 -&gt; _last == 1
  1977. od
  1978. }
  1979. </PRE></TT></DL>
  1980. The initial value of
  1981. <TT>_last</TT>
  1982. is zero.
  1983. <br>&#32;<br>
  1984. Three predefined functions are specifically intended to be used in
  1985. <TT>never</TT>
  1986. claims, and may not be used elsewhere in a model:
  1987. <TT>pc_value(pid)</TT>,
  1988. <TT>enabled(pid)</TT>,
  1989. <TT>procname[pid]@label</TT>.
  1990. <br>&#32;<br>
  1991. The function
  1992. <TT>pc_value(pid)</TT>
  1993. returns the current control state
  1994. of the process with instantiation number
  1995. <TT>pid</TT>,
  1996. or zero if no such process exists.
  1997. <br>&#32;<br>
  1998. Example:
  1999. <DL><DT><DD><TT><PRE>
  2000. never {
  2001. /* Whimsical use: claim that it is impossible
  2002. * for process 1 to remain in the same control
  2003. * state as process 2, or one with smaller value.
  2004. */
  2005. accept: do
  2006. :: pc_value(1) &lt;= pc_value(2)
  2007. od
  2008. }
  2009. </PRE></TT></DL>
  2010. The function
  2011. <TT>enabled(pid)</TT>
  2012. tells whether the process with instantiation number
  2013. <TT>pid</TT>
  2014. has an executable statement that it can execute next.
  2015. <br>&#32;<br>
  2016. Example:
  2017. <DL><DT><DD><TT><PRE>
  2018. never {
  2019. /* it is not possible for the process with pid=1
  2020. * to remain enabled without ever executing
  2021. */
  2022. accept:
  2023. do
  2024. :: _last != 1 &amp;&amp; enabled(1)
  2025. od
  2026. }
  2027. </PRE></TT></DL>
  2028. The last function
  2029. <TT>procname[pid]@label</TT>
  2030. tells whether the process with instantiation number
  2031. <TT>pid</TT>
  2032. is currently in the state labeled with
  2033. <TT>label</TT>
  2034. in
  2035. <TT>proctype procname</TT>.
  2036. It is an error if the process referred to is not an instantiation
  2037. of that proctype.
  2038. <H4>2 Verifications with <small>SPIN</small>
  2039. </H4>
  2040. <br>&#32;<br>
  2041. The easiest way to use <small>SPIN</small> is probably on a Windows terminal
  2042. with the Tcl/Tk implementation of <small>XSPIN</small>.
  2043. All functionality of <small>SPIN</small>, however, is accessible from
  2044. any plain ASCII terminal, and there is something to be
  2045. said for directly interacting with the tool itself.
  2046. <br>&#32;<br>
  2047. The description in this paper gives a short walk-through of
  2048. a common mode of operation in using the verifier.
  2049. A more tutorial style description of the verification
  2050. process can be found in [Ho93].
  2051. More detail on the verification of large systems with the
  2052. help of <small>SPIN</small>'s supertrace (bitstate) verification algorithm
  2053. can be found in [Ho95].
  2054. <DL>
  2055. <DT><DT>&#32;<DD>
  2056. <DL><DD>
  2057. <br>
  2058. *
  2059. Random and interactive simulations (section 2.1),
  2060. <br>
  2061. *
  2062. Generating a verifier (section 2.2),
  2063. <br>
  2064. *
  2065. Compilation for different types of searches (section 2.3),
  2066. <br>
  2067. *
  2068. Performing the verification (section 2.4),
  2069. <br>
  2070. *
  2071. Inspecting error traces produced by the verifier (section 2.5),
  2072. <br>
  2073. *
  2074. Exploiting partial order reductions (section 2.6).
  2075. </DL>
  2076. </dl>
  2077. <br>&#32;<br>
  2078. <H4>2.1 Random and Interactive Simulations
  2079. </H4>
  2080. <br>&#32;<br>
  2081. Given a model in <small>PROMELA</small>, say stored in a file called
  2082. <TT>spec</TT>,
  2083. the easiest mode of operation is to perform a random simulation.
  2084. For instance,
  2085. <DL><DT><DD><TT><PRE>
  2086. spin -p spec
  2087. </PRE></TT></DL>
  2088. tells <small>SPIN</small> to perform a random simulation, while printing the
  2089. process moves selected for execution at each step (by default
  2090. nothing is printed, other than explicit
  2091. <TT>printf</TT>
  2092. statements that appear in the model itself).
  2093. A range of options exists to make the traces more verbose,
  2094. e.g., by adding printouts of local variables (add option
  2095. <TT>-l</TT>),
  2096. global variables (add option
  2097. <TT>-g</TT>),
  2098. send statements (add option
  2099. <TT>-s</TT>),
  2100. or receive statements (add option
  2101. <TT>-r</TT>).
  2102. Use option
  2103. <TT>-n</TT>N
  2104. (with N any number) to fix the seed on <small>SPIN</small>'s internal
  2105. random number generator, and thus make the simulation runs
  2106. reproducible.
  2107. By default the current time is used to seed the random number
  2108. generator.
  2109. For instance:
  2110. <DL><DT><DD><TT><PRE>
  2111. spin -p -l -g -r -s -n1 spec
  2112. </PRE></TT></DL>
  2113. <br>&#32;<br>
  2114. If you don't like the system randomly resolving non-deterministic
  2115. choices for you, you can select an interactive simulation:
  2116. <DL><DT><DD><TT><PRE>
  2117. spin -i -p spec
  2118. </PRE></TT></DL>
  2119. In this case you will be offered a menu with choices each time
  2120. the execution could proceed in more than one way.
  2121. <br>&#32;<br>
  2122. Simulations, of course, are intended primarily for the
  2123. debugging of a model. They cannot prove anything about it.
  2124. Assertions will be evaluated during simulation runs, and
  2125. any violations that result will be reported, but none of
  2126. the other correctness requirements can be checked in this way.
  2127. <H4>2.2 Generating the Verifier
  2128. </H4>
  2129. <br>&#32;<br>
  2130. A model-specific verifier is generated as follows:
  2131. <DL><DT><DD><TT><PRE>
  2132. spin -a spec
  2133. </PRE></TT></DL>
  2134. This generates a C program in a number of files (with names
  2135. starting with
  2136. <TT>pan</TT>).
  2137. <H4>2.3 Compiling the Verifier
  2138. </H4>
  2139. <br>&#32;<br>
  2140. At this point it is good to know the physical limitations of
  2141. the computer system that you will run the verification on.
  2142. If you know how much physical (not virtual) memory your system
  2143. has, you can take advantage of that.
  2144. Initially, you can simply compile the verifier for a straight
  2145. exhaustive verification run (constituting the strongest type
  2146. of proof if it can be completed).
  2147. Compile as follows.
  2148. <DL><DT><DD><TT><PRE>
  2149. pcc -o pan pan.c # standard exhaustive search
  2150. </PRE></TT></DL>
  2151. If you know a memory bound that you want to restrict the run to
  2152. (e.g., to avoid paging), find the nearest power of 2 (e.g., 23
  2153. for the bound 2^&lt;small&gt;&lt;small&gt;&lt;small&gt;23&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt; bytes) and compile as follows.
  2154. <DL><DT><DD><TT><PRE>
  2155. pcc '-DMEMCNT=23' -o pan pan.c
  2156. </PRE></TT></DL>
  2157. or equivalently in terms of MegaBytes:
  2158. <DL><DT><DD><TT><PRE>
  2159. pcc '-DMEMLIM=8' -o pan pan.c
  2160. </PRE></TT></DL>
  2161. If the verifier runs out of memory before completing its task,
  2162. you can decide to increase the bound or to switch to a frugal
  2163. supertrace verification. In the latter case, compile as follows.
  2164. <DL><DT><DD><TT><PRE>
  2165. pcc -DBITSTATE -o pan pan.c
  2166. </PRE></TT></DL>
  2167. <H4>2.4 Performing the Verification
  2168. </H4>
  2169. <br>&#32;<br>
  2170. There are three specific decisions to make to
  2171. perform verifications optimally: estimating the
  2172. size of the reachable state space (section 2.4.1),
  2173. estimating the maximum length of a unique execution
  2174. sequence (2.4.2), and selecting the type of correctness
  2175. property (2.4.3).
  2176. No great harm is done if the estimates from the first two
  2177. steps are off. The feedback from the verifier usually provides
  2178. enough clues to determine quickly what the optimal settings
  2179. for peak performance should be.
  2180. <H4>2.4.1 Reachable States
  2181. </H4>
  2182. <br>&#32;<br>
  2183. For a standard exhaustive run, you can override the default choice
  2184. for the size for the hash table (2^&lt;/big&gt;&lt;/big&gt;&lt;/big&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;18&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt; slots) with option
  2185. <TT>-w</TT>.
  2186. For instance,
  2187. <DL><DT><DD><TT><PRE>
  2188. pan -w23
  2189. </PRE></TT></DL>
  2190. selects 2^&lt;/big&gt;&lt;/big&gt;&lt;/big&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;23&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt; slots.
  2191. The hash table size should optimally be roughly equal to the number of
  2192. reachable states you expect (within say a factor of two or three).
  2193. Too large a number merely wastes memory, too low a number wastes
  2194. CPU time, but neither can affect the correctness of the result.
  2195. <br>&#32;<br>
  2196. For a supertrace run, the hash table <I>is</I> the memory arena, and
  2197. you can override the default of 2^&lt;/big&gt;&lt;/big&gt;&lt;/big&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;22&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt; bits with any other number.
  2198. Set it to the maximum size of physical memory you can grab without
  2199. making the system page, again within a factor of say two or three.
  2200. Use, for instance
  2201. <TT>-w23</TT>
  2202. if you expect 8 million reachable states and have access to at least
  2203. 8 million (2^&lt;/big&gt;&lt;/big&gt;&lt;/big&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;23&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt;) bits of memory (i.e., 2^&lt;/big&gt;&lt;/big&gt;&lt;/big&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;20&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt; or 1 Megabyte of RAM).
  2204. <H4>2.4.2 Search Depth
  2205. </H4>
  2206. <br>&#32;<br>
  2207. By default the analyzers have a search depth restriction of 10,000 steps.
  2208. If this isn't enough, the search will truncate at 9,999 steps (watch for
  2209. it in the printout).
  2210. Define a different search depth with the -m flag.
  2211. <DL><DT><DD><TT><PRE>
  2212. pan -m100000
  2213. </PRE></TT></DL>
  2214. If you exceed also this limit, it is probably good to take some
  2215. time to consider if the model you have specified is indeed finite.
  2216. Check, for instance, if no unbounded number of processes is created.
  2217. If satisfied that the model is finite, increase the search depth at
  2218. least as far as is required to avoid truncation completely.
  2219. <br>&#32;<br>
  2220. If you find a particularly nasty error that takes a large number of steps
  2221. to hit, you may also set lower search depths to find the shortest variant
  2222. of an error sequence.
  2223. <DL><DT><DD><TT><PRE>
  2224. pan -m40
  2225. </PRE></TT></DL>
  2226. Go up or down by powers of two until you find the place where the
  2227. error first appears or disappears and then home in on the first
  2228. depth where the error becomes apparent, and use the error trail of
  2229. that verification run for guided simulation.
  2230. <br>&#32;<br>
  2231. Note that if a run with a given search depth fails to find
  2232. an error, this does not necessarily mean that no violation of a
  2233. correctness requirement is possible within that number of steps.
  2234. The verifier performs its search for errors by using a standard
  2235. depth-first graph search. If the search is truncated at N steps,
  2236. and a state at level N-1 happens to be reachable also within fewer
  2237. steps from the initial state, the second time it is reached it
  2238. will not be explored again, and thus neither will its successors.
  2239. Those successors may contain errors states that are reachable within
  2240. N steps from the initial state.
  2241. Normally, the verification should be run in such a way that no
  2242. execution paths can be truncated, but to force the complete exploration
  2243. of also truncated searches one can override the defaults with a compile-time
  2244. flag
  2245. <TT>-DREACH</TT>.
  2246. When the verifier is compiled with that additional directive, the depth at
  2247. which each state is visited is remembered, and a state is now considered
  2248. unvisited if it is revisited via a shorter path later in the search.
  2249. (This option cannot be used with a supertrace search.)
  2250. <H4>2.4.3 Liveness or Safety Verification
  2251. </H4>
  2252. <br>&#32;<br>
  2253. For the last, and perhaps the most critical, runtime decision:
  2254. it must be decided if the system is to be checked for safety
  2255. violations or for liveness violations.
  2256. <DL><DT><DD><TT><PRE>
  2257. pan -l # search for non-progress cycles
  2258. pan -a # search for acceptance cycles
  2259. </PRE></TT></DL>
  2260. (In the first case, though, you must compile pan.c with -DNP as an
  2261. additional directive. If you forget, the executable will remind you.)
  2262. If you don't use either of the above two options, the default types of
  2263. correctness properties are checked (assertion violations,
  2264. completeness, race conditions, etc.).
  2265. Note that the use of a
  2266. <TT>never</TT>
  2267. claim that contains
  2268. <TT>accept</TT>
  2269. labels requires the use of the
  2270. <TT>-a</TT>
  2271. flag for complete verification.
  2272. <br>&#32;<br>
  2273. Adding option
  2274. <TT>-f</TT>
  2275. restricts the search for liveness properties further under
  2276. a standard <I>weak fairness</I> constraint:
  2277. <DL><DT><DD><TT><PRE>
  2278. pan -f -l # search for weakly fair non-progress cycles
  2279. pan -f -a # search for weakly fair acceptance cycles
  2280. </PRE></TT></DL>
  2281. With this constraint, each process is required to appear
  2282. infinitely often in the infinite trace that constitutes
  2283. the violation of a liveness property (e.g., a non-progress cycle
  2284. or an acceptance cycle), unless it is permanently blocked
  2285. (i.e., has no executable statements after a certain point in
  2286. the trace is reached).
  2287. Adding the fairness constraint increases the time complexity
  2288. of the verification by a factor that is linear in the number
  2289. of active processes.
  2290. <br>&#32;<br>
  2291. By default, the verifier will report on unreachable code in
  2292. the model only when a verification run is successfully
  2293. completed.
  2294. This default behavior can be turned off with the runtime option
  2295. <TT>-n</TT>,
  2296. as in:
  2297. <DL><DT><DD><TT><PRE>
  2298. pan -n -f -a
  2299. </PRE></TT></DL>
  2300. (The order in which the options such as these are listed is
  2301. always irrelevant.)
  2302. A brief explanation of these and other runtime options can
  2303. be determined by typing:
  2304. <DL><DT><DD><TT><PRE>
  2305. pan --
  2306. </PRE></TT></DL>
  2307. <H4>2.5 Inspecting Error Traces
  2308. </H4>
  2309. <br>&#32;<br>
  2310. If the verification run reports an error,
  2311. any error, </big></big></big><small>SPIN</small> dumps an error trail into a file named
  2312. <TT>spec.trail</TT>,
  2313. where
  2314. <TT>spec</TT>
  2315. is the name of your original <small>PROMELA</small> file.
  2316. To inspect the trail, and determine the cause of the error,
  2317. you must use the guided simulation option.
  2318. For instance:
  2319. <DL><DT><DD><TT><PRE>
  2320. spin -t -c spec
  2321. </PRE></TT></DL>
  2322. gives you a summary of message exchanges in the trail, or
  2323. <DL><DT><DD><TT><PRE>
  2324. spin -t -p spec
  2325. </PRE></TT></DL>
  2326. gives a printout of every single step executed.
  2327. Add as many extra or different options as you need to pin down the error:
  2328. <DL><DT><DD><TT><PRE>
  2329. spin -t -r -s -l -g spec
  2330. </PRE></TT></DL>
  2331. Make sure the file
  2332. <TT>spec</TT>
  2333. didn't change since you generated the analyzer from it.
  2334. <br>&#32;<br>
  2335. If you find non-progress cycles, add or delete progress labels
  2336. and repeat the verification until you are content that you have found what
  2337. you were looking for.
  2338. <br>&#32;<br>
  2339. If you are not interested in the first error reported,
  2340. use pan option
  2341. <TT>-c</TT>
  2342. to report on specific others:
  2343. <DL><DT><DD><TT><PRE>
  2344. pan -c3
  2345. </PRE></TT></DL>
  2346. ignores the first two errors and reports on the third one that
  2347. is discovered.
  2348. If you just want to count all errors and not see them, use
  2349. <DL><DT><DD><TT><PRE>
  2350. pan -c0
  2351. </PRE></TT></DL>
  2352. <H4>State Assignments
  2353. </H4>
  2354. <br>&#32;<br>
  2355. Internally, the verifiers produced by <small>SPIN</small> deal with a formalization of
  2356. a <small>PROMELA</small> model in terms of extended finite state machines.
  2357. <small>SPIN</small> therefore assigns state numbers to all statements in the model.
  2358. The state numbers are listed in all the relevant output to make it
  2359. completely unambiguous (source line references unfortunately do not
  2360. have that property).
  2361. To confirm the precise state assignments, there is a runtime option
  2362. to the analyzer generated:
  2363. <DL><DT><DD><TT><PRE>
  2364. pan -d # print state machines
  2365. </PRE></TT></DL>
  2366. which will print out a table with all state assignments for each
  2367. <TT>proctype</TT>
  2368. in the model.
  2369. <H4>2.6 Exploiting Partial Order Reductions
  2370. </H4>
  2371. <br>&#32;<br>
  2372. The search algorithm used by <small>SPIN</small> is optimized
  2373. according to the rules of a partial order theory explained in [HoPe94].
  2374. The effect of the reduction, however, can be increased considerably if the verifier
  2375. has extra information about the access of processes to global
  2376. message channels.
  2377. For this purpose, there are two keywords in the language that
  2378. allow one to assert that specific channels are used exclusively
  2379. by specific processes.
  2380. For example, the assertions
  2381. <DL><DT><DD><TT><PRE>
  2382. xr q1;
  2383. xs q2;
  2384. </PRE></TT></DL>
  2385. claim that the process that executes them is the <I>only</I> process
  2386. that will receive messages from channel
  2387. <TT>q1</TT>,
  2388. and the <I>only</I> process that will send messages to channel
  2389. <TT>q2</TT>.
  2390. <br>&#32;<br>
  2391. If an exclusive usage assertion turns out to be invalid, the
  2392. verifier will be able to detect this, and report it as a violation
  2393. of an implicit correctness requirement.
  2394. <br>&#32;<br>
  2395. Every read or write access to a message channel can introduce
  2396. new dependencies that may diminish the maximum effect of the
  2397. partial order reduction strategies.
  2398. If, for instance, a process uses the
  2399. <TT>len</TT>
  2400. function to check the number of messages stored in a channel,
  2401. this counts as a read access, which can in some cases invalidate
  2402. an exclusive access pattern that might otherwise exist.
  2403. There are two special functions that can be used to poll the
  2404. size of a channel in a safe way that is compatible with the
  2405. reduction strategy.
  2406. <br>&#32;<br>
  2407. The expression
  2408. <TT>nfull(qname)</TT>
  2409. returns true if channel
  2410. <TT>qname</TT>
  2411. is not full, and
  2412. <TT>nempty(qname)</TT>
  2413. returns true if channel
  2414. <TT>qname</TT>
  2415. contains at least one message.
  2416. Note that the parser will not recognize the free form expressions
  2417. <TT>!full(qname)</TT>
  2418. and
  2419. <TT>!empty(qname)</TT>
  2420. as equally safe, and it will forbid constructions such as
  2421. <TT>!nfull(qname)</TT>
  2422. or
  2423. <TT>!nempty(qname)</TT>.
  2424. More detail on this aspect of the reduction algorithms can be
  2425. found in [HoPe94].
  2426. <H4>Keywords
  2427. </H4>
  2428. <br>&#32;<br>
  2429. For reference, the following table contains all the keywords,
  2430. predefined functions, predefined variables, and
  2431. special label-prefixes of the language <small>PROMELA</small>,
  2432. and refers to the section of this paper in
  2433. which they were discussed.
  2434. <br><img src="-.19126692.gif"><br>
  2435. <H4>References
  2436. </H4>
  2437. <br>&#32;<br>
  2438. [Ho91]
  2439. G.J. Holzmann,
  2440. Design and Validation of Computer Protocols,
  2441. Prentice Hall, 1991.
  2442. <br>&#32;<br>
  2443. [Ho93]
  2444. G.J. Holzmann, ``Tutorial: Design and Validation of Protocols,''
  2445. Computer Networks and ISDN Systems,
  2446. 1993, Vol. 25, No. 9, pp. 981-1017.
  2447. <br>&#32;<br>
  2448. [HoPe94]
  2449. G.J. Holzmann and D.A. Peled, ``An improvement in
  2450. formal verification,''
  2451. Proc. 7th Int. Conf. on Formal Description Techniques,
  2452. FORTE94, Berne, Switzerland. October 1994.
  2453. <br>&#32;<br>
  2454. [Ho95]
  2455. G.J. Holzmann, ``An Analysis of Bitstate Hashing,''
  2456. technical report 2/95, available from author.
  2457. <br>&#32;<br>
  2458. [HS99]
  2459. G.J. Holzmann, ``Software model checking: extracting
  2460. verification models from source code,''
  2461. Proc. Formal Methods in Software Engineering and Distributed
  2462. Systems,
  2463. PSTV/FORTE99, Beijng, China, Oct. 1999, Kluwer,pp. 481-497.
  2464. <br>&#32;<br>
  2465. <A href=http://www.lucent.com/copyright.html>
  2466. Copyright</A> &#169; 2004 Lucent Technologies Inc. All rights reserved.
  2467. </body></html>