多线程理解(不)可变对象的共享变量
作者:
蕴重Liu | 来源:发表于
2019-07-16 17:59 被阅读0次if __name__ == '__main__':
# file = ''
# read_excel(file.read())
import threading
balance = 1
ccbalance = 1
bbalance = {'count':0 }
# 操作银行账户中的余额
def run_thread(balance):
for i in range(10000000):
balance += 1
ccbalance = ccbalance + 1
bbalance['count'] += 1
t1 = threading.Thread(target=run_thread, args=(balance, ))
t2 = threading.Thread(target=run_thread, args=(balance, ))
t1.start()
t2.start()
t1.join()
t2.join()
print(balance)
print(ccbalance)
print(bbalance['count'])
输出:
1
1
15934810
本文标题:多线程理解(不)可变对象的共享变量
本文链接:https://www.haomeiwen.com/subject/bpmtlctx.html
网友评论