示例代码如下:

import threading
import time

total = 0


def add():
    global total
    for i in range(100000):
        total += 1

    print(total)


def minus():
    global total
    for i in range(100000):
        total -= 1

    print(total)


def main():
    # add()
    # minu()

    t1 = threading.Thread(target=add)
    t2 = threading.Thread(target=minus)
    t1.start()
    t2.start()

    print('程序执行结束...')


if __name__ == '__main__':
    main()