Commit | Line | Data |
---|---|---|
d4de4869 MD |
1 | /* |
2 | * futex.spin: Promela code to validate futex wakeup algorithm. | |
3 | * | |
4 | * Algorithm verified : | |
5 | * | |
6 | * queue = 0; | |
7 | * fut = 0; | |
8 | * runvar = 0; | |
9 | * | |
10 | * Waker | |
11 | * queue = 1; | |
12 | * if (fut == -1) { | |
13 | * fut = 0; | |
14 | * } | |
15 | * | |
16 | * Waiter | |
17 | * while (1) { | |
18 | * progress: | |
19 | * fut = fut - 1; | |
20 | * if (queue == 1) { | |
21 | * fut = 0; | |
22 | * } else { | |
23 | * if (fut == -1) { | |
24 | * while (fut == -1) { } | |
25 | * } | |
26 | * } | |
27 | * queue = 0; | |
28 | * } | |
29 | * | |
30 | * if queue = 1, then !_np | |
31 | * | |
32 | * This program is free software; you can redistribute it and/or modify | |
33 | * it under the terms of the GNU General Public License as published by | |
34 | * the Free Software Foundation; either version 2 of the License, or | |
35 | * (at your option) any later version. | |
36 | * | |
37 | * This program is distributed in the hope that it will be useful, | |
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
40 | * GNU General Public License for more details. | |
41 | * | |
42 | * You should have received a copy of the GNU General Public License | |
43 | * along with this program; if not, write to the Free Software | |
44 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
45 | * | |
46 | * Copyright (c) 2009 Mathieu Desnoyers | |
47 | */ | |
48 | ||
29f38067 MD |
49 | #define get_pid() (_pid) |
50 | ||
51 | int queue[2] = 0; | |
d4de4869 MD |
52 | int fut = 0; |
53 | ||
29f38067 | 54 | active [2] proctype waker() |
d4de4869 | 55 | { |
29f38067 MD |
56 | assert(get_pid() < 2); |
57 | ||
58 | queue[get_pid()] = 1; | |
d4de4869 MD |
59 | |
60 | if | |
61 | :: (fut == -1) -> | |
62 | fut = 0; | |
63 | :: else -> | |
64 | skip; | |
65 | fi; | |
66 | ||
29f38067 | 67 | queue[get_pid()] = 1; |
d4de4869 MD |
68 | |
69 | if | |
70 | :: (fut == -1) -> | |
71 | fut = 0; | |
72 | :: else -> | |
73 | skip; | |
74 | fi; | |
75 | ||
76 | #ifdef INJ_QUEUE_NO_WAKE | |
29f38067 | 77 | queue[get_pid()] = 1; |
d4de4869 MD |
78 | #endif |
79 | } | |
80 | ||
81 | ||
82 | active proctype waiter() | |
83 | { | |
84 | do | |
85 | :: 1 -> | |
86 | #ifndef INJ_LATE_DEC | |
87 | fut = fut - 1; | |
88 | #endif | |
89 | if | |
29f38067 | 90 | :: (queue[0] == 1 || queue[1] == 1) -> |
d4de4869 MD |
91 | #ifndef INJ_LATE_DEC |
92 | fut = 0; | |
93 | #endif | |
94 | skip; | |
95 | :: else -> | |
96 | #ifdef INJ_LATE_DEC | |
97 | fut = fut - 1; | |
98 | #endif | |
99 | if | |
100 | :: (fut == -1) -> | |
101 | do | |
102 | :: 1 -> | |
103 | if | |
104 | :: (fut == -1) -> | |
d4de4869 MD |
105 | skip; |
106 | :: else -> | |
107 | break; | |
108 | fi; | |
109 | od; | |
110 | :: else -> | |
111 | skip; | |
112 | fi; | |
113 | fi; | |
9b35d5dc | 114 | progress: |
29f38067 MD |
115 | if |
116 | :: queue[0] == 1 -> | |
117 | queue[0] = 0; | |
118 | fi; | |
119 | if | |
120 | :: queue[1] == 1 -> | |
121 | queue[1] = 0; | |
122 | fi; | |
d4de4869 MD |
123 | od; |
124 | } |