这是我的代码:
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
for i in range(1000000):
x-=1
def run():
a().start()
b().start()
//after both thread done
print x
run()
Run Code Online (Sandbox Code Playgroud)
我希望这显示我0(x = 0),但每次我运行它的结果是非常不同(小于零)
它有什么问题?