+ -
当前位置:首页 → 问答吧 → thread问题求救

thread问题求救

时间:2011-04-03

来源:互联网

import threading

counter = 0

class MyThread ( threading.Thread ):
  def run ( self ):
    global counter
    for i in range(0,10000):
      counter = counter + 1

t = list()

for x in range(0,20):
  t.append(MyThread())
  t[x].start()

for x in range(0,20):
  t[x].join()

print counter

The program has been executed 10 times on a suitable machine (e.g., recent Linux version, recent python version), which has produced the following of output:
43491
34732
58987
41933
140221
46398
131750
45778
55603
88844

Run the program 5 times and report the output. Explain the differences in output.

作者: zhltmvp   发布时间: 2011-04-03

Are u in UW....haha~~~

作者: liyphoenix   发布时间: 2011-04-03