铁乐学python_Day42_锁和队列 例:多个线程抢占资源的情况 from threading import Thread import time def work(): global n temp = n time.sleep(0.1) n = temp - 1 if __name__ == '__main__': n = 100 l = [] for i in range(100): p = Thread(target=work) l.append(p) p.start() for p…
一.多线程 1.顺序执行单个线程,注意要顺序执行的话,需要用join. #coding=utf-8 from threading import Thread import time def my_counter(): i = 0 for _ in range(100000000): i = i + 1 return True def main(): thread_array = {} start_time = time.time() for tid in range(2): t = Thread…