1 carnegie mellon universityspin examplesflavio lerda bug catching15-398 spin examples
TRANSCRIPT
![Page 1: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/1.jpg)
1
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
SPIN Examples
![Page 2: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/2.jpg)
2
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
![Page 3: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/3.jpg)
3
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
![Page 4: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/4.jpg)
4
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
![Page 5: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/5.jpg)
5
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
![Page 6: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/6.jpg)
6
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
flag1 == 0 || turn == 1
![Page 7: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/7.jpg)
7
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
![Page 8: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/8.jpg)
8
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
![Page 9: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/9.jpg)
9
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
CriticalSection
![Page 10: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/10.jpg)
10
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
![Page 11: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/11.jpg)
11
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion
• Peterson’s solution to the mutual exclusion problem
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
![Page 12: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/12.jpg)
12
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
proctype mutex0() {
}
![Page 13: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/13.jpg)
13
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
proctype mutex0() {
}
![Page 14: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/14.jpg)
14
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
}
![Page 15: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/15.jpg)
15
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
flag[0] = 1;
}
![Page 16: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/16.jpg)
16
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
flag[0] = 1;
turn = 0;
}
![Page 17: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/17.jpg)
17
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
flag[0] = 1;
turn = 0;
(flag[1] == 0 || turn == 0);
}
![Page 18: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/18.jpg)
18
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
flag[0] = 1;
turn = 0;
(flag[1] == 0 || turn == 0);
/* critical section */
}
![Page 19: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/19.jpg)
19
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
flag[0] = 1;
turn = 0;
(flag[1] == 0 || turn == 0);
/* critical section */
flag[0] = 0;
}
![Page 20: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/20.jpg)
20
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPIN
flag0=1
turn=0
flag1 == 0 || turn == 1
flag1 != 0 && turn != 1
flag0=0
CriticalSection
bool turn;
bool flag[2];
proctype mutex0() {
again:
flag[0] = 1;
turn = 0;
(flag[1] == 0 || turn == 0);
/* critical section */
flag[0] = 0;
goto again;
}
![Page 21: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/21.jpg)
21
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPINbool turn, flag[2];
active [2] proctype user()
{
assert(_pid == 0 || __pid == 1);
again:
flag[_pid] = 1;
turn = _pid;
(flag[1 - _pid] == 0 || turn == 1 - _pid);
/* critical section */
flag[_pid] = 0;
goto again;
}
Active process:automatically creates instances of processes
_pid:Identifier of the process
assert:Checks that there are only at most two instances with identifiers 0 and 1
![Page 22: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/22.jpg)
22
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPINbool turn, flag[2];
byte ncrit;
active [2] proctype user()
{
assert(_pid == 0 || __pid == 1);
again:
flag[_pid] = 1;
turn = _pid;
(flag[1 - _pid] == 0 || turn == 1 - _pid);
ncrit++;
assert(ncrit == 1); /* critical section */
ncrit--;
flag[_pid] = 0;
goto again;
}
ncrit:Counts the number ofProcess in the critical section
assert:Checks that there are alwaysat most one process in thecritical section
![Page 23: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/23.jpg)
23
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Mutual Exclusion in SPINbool turn, flag[2];
bool critical[2];
active [2] proctype user()
{
assert(_pid == 0 || __pid == 1);
again:
flag[_pid] = 1;
turn = _pid;
(flag[1 - _pid] == 0 || turn == 1 - _pid);
critical[_pid] = 1;
/* critical section */
critical[_pid] = 0;
flag[_pid] = 0;
goto again;
}
LTL Properties:
[] (critial[0] || critical[1])
[] <> (critical[0])[] <> (critical[1])
[] (critical[0] -> (critial[0] U (!critical[0] && ((!critical[0] && !critical[1]) U critical[1]))))[] (critical[1] -> (critial[1] U (!critical[1] && ((!critical[1] && !critical[0]) U critical[0]))))
![Page 24: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/24.jpg)
24
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Alternating Bit Protocol
• Two processes want to communicate
• They want acknowledge of received messages
• Sending window of one message
• Each message is identified by one bit
• Alternating values of the identifier
![Page 25: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/25.jpg)
25
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Alternating Bit ProtocolSender Receiver
msg0
ack0
msg1
ack1
msg0
ack0
msg1
![Page 26: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/26.jpg)
26
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Alternating Bit ProtocolSender Receiver
msg0
ack1
msg0
ack0
![Page 27: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/27.jpg)
27
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Alternating Bit ProtocolSender Receiver
msg0
ack0
msg1
ack1
msg0
![Page 28: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/28.jpg)
28
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Sender Processactive proctype Sender(){ do :: if :: receiver?msg0; :: skip fi; do :: sender?ack0 -> break :: sender?ack1 :: timeout -> if :: receiver!msg0; :: skip fi; od;
:: if :: receiver?msg1; :: skip fi; do :: sender?ack1 -> break :: sender?ack0 :: timeout -> if :: receiver!msg1; :: skip fi; od; od;}
![Page 29: 1 Carnegie Mellon UniversitySPIN ExamplesFlavio Lerda Bug Catching15-398 SPIN Examples](https://reader036.vdocuments.site/reader036/viewer/2022081602/551a9172550346e0158b5185/html5/thumbnails/29.jpg)
29
Carnegie Mellon University SPIN ExamplesFlavio Lerda
Bug Catching 15-398
Receiver Processactive proctype Receiver(){ do :: do :: receiver?msg0 -> sender!ack0; break; :: receiver?msg1 -> server!ack1 od do :: receiver?msg1 -> sender!ack1; break; :: receiver?msg0 -> server!ack0 od od}
mtype = { msg0, msg1, ack0, ack1 }chan sender = [1] of { mtype };chan receiver = [1] of { mtype };