def main(): lunch_break = threading.Lock() finish = threading.Event() allen = Thread(work, 'Allen', lunch_break, finish) bob = Thread(work, 'Bob', lunch_break, finish) time.sleep(.4) finish.set()
def main(): a1_action = Semaphore(0) b1_action = Semaphore(0) a = Thread(a_task, a1_action, b1_action) b = Thread(b_task, a1_action, b1_action) a.join() b.join()
def main(): barrier = threading.Barrier(total_threads, show_barrier) counter_lock = threading.Lock() threads = [Thread(work, t, barrier) for t in range(total_threads)] for thread in threads: thread.join()
def main(): barrier = Semaphore(0) counter_lock = threading.Lock() threads = [ Thread(work, t, barrier, counter_lock) for t in range(total_threads) ] for thread in threads: thread.join()
def main(): updating = Lock() threads = [Thread(update, t, updating) for t in range(100)] for thread in threads: thread.join() print('\ncount:', count)
def main(): reading = Semaphore(0) reader = Thread(read_task, reading) display = Thread(display_task, reading) reader.join() display.join()
def main(): q = queue.Queue(1) reader = Thread(read_task, q) display = Thread(display_task, q) reader.join() display.join()
def main(): threads = [Thread(update) for t in range(100)] for thread in threads: thread.join() print('count:', count)
def main(): updating = Semaphore(1) threads = [Thread(update, t, updating) for t in range(100)] for thread in threads: thread.join() print('count:', count)
def main(): call = threading.Event() Thread(allen_day, call) Thread(bob_day, call)