def whispers(options): import threading try: import Queue as queue except ImportError: import queue leftmost = queue.Queue() left = leftmost for i in benchlib.range(options.threads): right = queue.Queue() t = threading.Thread(target=whisper, args=(left, right)) t.daemon = True t.start() left = right for i in benchlib.range(options.jobs): right.put(1) for i in benchlib.range(options.jobs): n = leftmost.get() assert n == options.threads + 1
def threadpool(options): import threading try: import Queue as queue except ImportError: import queue src = queue.Queue() dst = queue.Queue() for i in benchlib.range(options.threads): t = threading.Thread(target=worker, args=(src, dst)) t.daemon = True t.start() for i in benchlib.range(options.rounds): for j in benchlib.range(options.jobs): src.put(1) for j in benchlib.range(options.jobs): n = dst.get() assert n == 2
def sleepless(options): import threading cond = threading.Condition(threading.Lock()) threads = [] for i in benchlib.range(options.threads): t = threading.Thread(target=sleep, args=(cond, options.timeout)) t.daemon = True t.start() threads.append(t) for t in threads: t.join()