Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import threading
- n = 0
- n_lock = threading.Lock()
- def f(a, b):
- global n
- for i in range(a, b+1):
- n_lock.acquire()
- n += i*i
- n_lock.release()
- t1 = threading.Thread(target=f, args=(1, 200000))
- t2 = threading.Thread(target=f, args=(200001, 500000))
- t3 = threading.Thread(target=f, args=(500001, 800000))
- t4 = threading.Thread(target=f, args=(800001, 1000000))
- t1.start()
- t2.start()
- t3.start()
- t4.start()
- t1.join()
- t2.join()
- t3.join()
- t4.join()
- print(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement