1、在Chang-Roberts算法中,每个初始进程计算所有初始进程的标识表,计算之后具有最小标识的进程被选中,通过环网,每个初始进程发送一个它自己标识的令牌,这个令牌被所有进程转发。假设信道是fifo的,某个初始进程必须在其他初始进程接到令牌之前,产生它的令牌当初始里程P接到它自己的返回令牌,所有初始进程的令牌已经过P,P当选,当且仅当P是初始里程中的最小的。
2、算法
var Listp:set of P init {p};
statep;
begin if p is initiator then
begin statep:=cand;send <tok,p> to Nextp;receive <tok,q>;
while q≠p do
begin Listp:=Listp∪{q};
send <tok,q> to Nextp;receive <tok,q>
end;
if p=min(Listp) then statep:=leader
else statep:=lost
end
else while true do
begin receive <tok,q>;send <tok,q> nto Nextp;
if statep:=sleep then statep:=lost
end
end