resource worker const int n = 1000 const int p = 1000 const int infinity = 1000000 type weightrow = [n]int type work = rec(int source; int distance ) #type workpool = [p]cap(int) #optype resultchan(int,int) body worker(int me, weightrow myweight, cap (work) pool [0:p], cap (int) answer) int mindist int newdist int ackcount, parent bool active op getwork(var int distance) op putwork(int vertex, int distance) proc getwork(distance) { int source; work inwork, ackwork inwork.source = -2; inwork.distance = 0 ackwork.source = -2; ackwork.distance = 0 while (inwork.source == -2) { if (active and (ackcount == 0) and ?pool[me] == 0) { active = false; send pool[parent](ackwork) } receive pool[me](inwork) if (inwork.source == -2) { ackcount = ackcount-1 } } if (active) { send pool[inwork.source](ackwork) } else { active = true; parent = inwork.source } distance = inwork.distance } proc putwork(vertex,distance) { work outwork ackcount = ackcount + 1; outwork = work(me,distance) send pool[vertex](outwork) } ackcount = 0 active = false mindist = infinity getwork(newdist); while (newdist != -1) { if (newdist < mindist) { mindist = newdist; for [w=1 to n] { if (w != me) { if (myweight[w] < infinity) { putwork(w,mindist+myweight[w]) } } } } getwork(newdist); } send answer(mindist); end worker