示例#1
0
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
示例#2
0
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
示例#3
0
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()
示例#4
0
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()