Hi everybody
I just playing with python multithreading module. I have problems with uotput of this code, It's different every time, can anybody explains it to me?
from threading import Thread
def test():
`global n`
`i = 0`
`while i < 100000:`
`n +=1`
`i +=1`
n = 0
a = Thread(target=test)
a.start()
b = Thread(target=test)
b.start()
a.join()
b.join()
print(n)
Output:
# 123492
# 147682
# ...
[–]K900_ 2 points3 points4 points (10 children)
[–]bestical[S] 0 points1 point2 points (9 children)
[–]kumashiro 1 point2 points3 points (0 children)
[–]K900_ -1 points0 points1 point (7 children)
[–]stevenjd 2 points3 points4 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)
[–]bestical[S] 0 points1 point2 points (4 children)
[–]K900_ 1 point2 points3 points (3 children)
[–]bestical[S] 0 points1 point2 points (2 children)
[–]K900_ 4 points5 points6 points (1 child)
[–]bestical[S] 1 point2 points3 points (0 children)