從the Dave Cheney Blog,下面的代碼顯然會導致比賽的情況下,可以僅僅通過改變來解決func (RPC) version() int到func (*RPC) version() int: package main
import (
"fmt"
"time"
)
type RPC struct {
result int
done
這是我的代碼: import threading
x=0
class a(threading.thread)
def run(self):
global x
for i in range(1000000):
x+=1
class b(threading.thread)
def run(self):
global x
爲什麼在我的代碼中有一個競爭條件,當所有帳戶同步? class Transfer implements Runnable {
Konto fromAccount;
Konto toAccount;
Integer amount;
public void run() {
synchronized (fromAccount) {
i