尼玛早上6点就有人进来了,刚夜里3点还有人在隔壁通宵,今天疑似有点撞大运了。

这次的工作量可能不太够,所以尽量就啰嗦一点。

  • bakery算法,完整版,去掉choosing版,atomic和safe寄存器的考量
  • 一个raft协议的考察,使用udp去实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
process(i) {
while (true) {
choosing[i] = true;
number[i] = 1 + max(number[1], number[2], ..., number[n-1]);
choosing[i] = false;

for (j = 0; j < n; j++) {
while (choosing[j]);
while (number[j] != 0 && (number[j], j) < (number[i], i));
}

<critical section>

number[i] = 0;
}
}
1
2
3
4
5
6
T1: Send(T2, REQUEST_VOTE, term = 1)
T1: Send(T3, REQUEST_VOTE, term = 1)
T3: Recv(T1, REQUEST_VOTE, term = 1)
T2: Recv(T1, REQUEST_VOTE, term = 1)
T2: Send(T1, GRANT_VOTE)
T3: Send(T1, GRANT_VOTE)
1
2
3
4
5
6
T1: Send(T2, REQUEST_VOTE, term = 1)
T2: Recv(T1, REQUEST_VOTE, term = 1)
T2: Send(T1, GRANT_VOTE)
T1: Send(T3, REQUEST_VOTE, term = 1)
T3: Recv(T1, REQUEST_VOTE, term = 1)
T3: Send(T1, GRANT_VOTE)