python线程锁


# -*- coding:UTF-8 -*-
'''
Created on 2015年10月25日

@author: young
'''

import threading

balance = 0
lock = threading.Lock()

def run_thread(n):
    for i in range(100000):
        # 先要获取锁:
        lock.acquire()
        try:
            pass
        finally:
            # 改完了一定要释放锁:
            lock.release()




你可能感兴趣的:(python)