import threading
import time

number = 0
lock = threading.Lock()

def plus(lk):
    global number;
    lk.acquire()    # acquire lock
    for i in range(1000000):
        number += 1
    print("When %s completes ,number = %s\n"\
          %(threading.current_thread().getName(),number))
    lk.release()    #解锁

if __name__ == '__main__':
    for i in range(2):
        t = threading.Thread(target=plus,args=(lock,))
        t.start()

time.sleep(2)
print("when main thread completes,number = ",number)
b2369fee94bb226f8c99f3dc16f746de20498559
<mask token>


def plus(lk):
    global number
    lk.acquire()
    for i in range(1000000):
        number += 1
    print('When %s completes ,number = %s\n' % (threading.current_thread().
        getName(), number))
    lk.release()


<mask token>

<mask token>


def plus(lk):
    global number
    lk.acquire()
    for i in range(1000000):
        number += 1
    print('When %s completes ,number = %s\n' % (threading.current_thread().
        getName(), number))
    lk.release()


if __name__ == '__main__':
    for i in range(2):
        t = threading.Thread(target=plus, args=(lock,))
        t.start()
time.sleep(2)
print('when main thread completes,number = ', number)

<mask token>
number = 0
lock = threading.Lock()


def plus(lk):
    global number
    lk.acquire()
    for i in range(1000000):
        number += 1
    print('When %s completes ,number = %s\n' % (threading.current_thread().
        getName(), number))
    lk.release()


if __name__ == '__main__':
    for i in range(2):
        t = threading.Thread(target=plus, args=(lock,))
        t.start()
time.sleep(2)
print('when main thread completes,number = ', number)

import threading
import time
number = 0
lock = threading.Lock()


def plus(lk):
    global number
    lk.acquire()
    for i in range(1000000):
        number += 1
    print('When %s completes ,number = %s\n' % (threading.current_thread().
        getName(), number))
    lk.release()


if __name__ == '__main__':
    for i in range(2):
        t = threading.Thread(target=plus, args=(lock,))
        t.start()
time.sleep(2)
print('when main thread completes,number = ', number)

import threading
import time

number = 0
lock = threading.Lock()

def plus(lk):
    global number;
    lk.acquire()    # acquire lock
    for i in range(1000000):
        number += 1
    print("When %s completes ,number = %s\n"\
          %(threading.current_thread().getName(),number))
    lk.release()    #解锁

if __name__ == '__main__':
    for i in range(2):
        t = threading.Thread(target=plus,args=(lock,))
        t.start()

time.sleep(2)
print("when main thread completes,number = ",number)