/** * AsyncBFS * -- compute the distance from a root node * adapted from N. Lynch, p. 502 */ type Pid; var dist: [Pid] int; var parent: [Pid] Pid; const INF: int; axiom (INF == 10000); procedure Main () { var root: Pid; assume (forall p: Pid :: dist[p] == INF); call {:async} bfs(root, -1, root); return; } // choose a new parent if she is closer to the source than the previous procedure bfs (this: Pid, m: int, sender: Pid) { var neighbor: Pid; if ( m+1 < dist[this] ) { dist[this] := m + 1; parent[this] := sender; while (*) { havoc neighbor; assume neighbor != this; assume neighbor != sender; call {:async} bfs (neighbor, dist[this], this); } // Possible bugs? cannot forever get decreasing distances... } return; }