Examples of ReentrantLock


Examples of java.util.concurrent.locks.ReentrantLock

    protected static final int LIMIT = 32;
    // used for rehashing
    private Random random;

    public CoarseCuckooHashSet(int capacity) {
        lock = new ReentrantLock();
        table = (T[][]) new Object[2][capacity];
        size = capacity;
        random = new Random();
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

    public StripedCuckooHashSet(int capacity) {
        super(capacity);
        lock = new ReentrantLock[2][capacity];
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < capacity; j++) {
                lock[i][j] = new ReentrantLock();
            }
        }
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

    public RefinableCuckooHashSet(int capacity) {
        super(capacity);
        locks = new ReentrantLock[2][capacity];
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < capacity; j++) {
                locks[i][j] = new ReentrantLock();
            }
        }
        owner = new AtomicMarkableReference<Thread>(null, false);
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

        while(true) {
            do { // wait until not resizing
                who = owner.get(mark);
            } while(mark[0] && who != me);
            ReentrantLock[][] oldLocks = this.locks;
            ReentrantLock oldLock0 = oldLocks[0][hash0(x) % oldLocks[0].length];
            ReentrantLock oldLock1 = oldLocks[1][hash1(x) % oldLocks[1].length];
            oldLock0.lock(); // acquire locks
            oldLock1.lock();
            who = owner.get(mark);
            if((!mark[0] || who == me) && this.locks == oldLocks) { // recheck
                return;
            } else { //  unlock & try again
                oldLock0.unlock();
                oldLock1.unlock();
            }
        }
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

                List<T>[][] oldTable = table;
                table = (List<T>[][]) new List[2][capacity];
                locks = new ReentrantLock[2][capacity];
                for(int i = 0; i < 2; i++) {
                    for(int j = 0; j < capacity; j++) {
                        locks[i][j] = new ReentrantLock();
                    }
                }
                for(List<T>[] row : table) {
                    for(int i = 0; i < row.length; i++) {
                        row[i] = new ArrayList<T>(PROBE_SIZE);
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

    private final ILock writeLock; // writers apply here

    public FifoReadWriteLock() {
        readAcquires = readReleases = 0;
        writer = false;
        metaLock = new ReentrantLock();
        condition = metaLock.newCondition();
        readLock = new ReadLock();
        writeLock = new WriteLock();
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

    private static void start(final int num_threads, final int num_msgs, boolean oob, TimeScheduler timer) {
        final NAKACK nak=new NAKACK();
        final AtomicInteger counter=new AtomicInteger(num_msgs);
        final AtomicLong seqno=new AtomicLong(1);
        final AtomicInteger delivered_msgs=new AtomicInteger(0);
        final Lock lock=new ReentrantLock();
        final Condition all_msgs_delivered=lock.newCondition();
        final ConcurrentLinkedQueue<Long> delivered_msg_list=new ConcurrentLinkedQueue<Long>();
        final Address local_addr=Util.createRandomAddress("A");
        final Address sender=Util.createRandomAddress("B");


        if(timer == null)
            timer=new TimeScheduler2();
        nak.setTimer(timer);
        System.out.println("timer is a " + timer.getClass());

        nak.setDownProtocol(new Protocol() {public Object down(Event evt) {return null;}});

        nak.setUpProtocol(new Protocol() {
            public Object up(Event evt) {
                if(evt.getType() == Event.MSG) {
                    delivered_msgs.incrementAndGet();
                    NakAckHeader hdr=(NakAckHeader)((Message)evt.getArg()).getHeader(NAKACK_ID);
                    if(hdr != null)
                        delivered_msg_list.add(hdr.getSeqno());

                    if(delivered_msgs.get() >= num_msgs) {
                        lock.lock();
                        try {
                            all_msgs_delivered.signalAll();
                        }
                        finally {
                            lock.unlock();
                        }
                    }
                }
                return null;
            }
        });

        nak.setDiscardDeliveredMsgs(true);
        nak.down(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
        nak.down(new Event(Event.BECOME_SERVER));
        View view=new View(local_addr, 1, Arrays.asList(local_addr, sender));
        nak.down(new Event(Event.VIEW_CHANGE, view));

        MutableDigest digest=new MutableDigest();
        digest.add(local_addr, 0, 0, 0);
        digest.add(sender, 0, 0, 0);
        nak.down(new Event(Event.SET_DIGEST, digest));

        final CountDownLatch latch=new CountDownLatch(1);
        Sender[] adders=new Sender[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Sender(nak, latch, counter, seqno, oob, sender);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        lock.lock();
        try {
            while(delivered_msgs.get() < num_msgs) {
                try {
                    all_msgs_delivered.await(1000, TimeUnit.MILLISECONDS);
                    System.out.println("received " + delivered_msgs.get() + " msgs");
                }
                catch(InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        finally {
            lock.unlock();
        }

        long time=System.currentTimeMillis() - start;
        double requests_sec=num_msgs / (time / 1000.0);
        System.out.println("\nTime: " + time + " ms, " + Util.format(requests_sec) + " requests / sec\n");
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

    ReentrantLock lock;


    @BeforeMethod
    public void setUp() throws Exception {
        lock=new ReentrantLock();
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

        for(int i=0; i < outputs.length; i++)
            outputs[i]=new ExposedDataOutputStream(outs[i]);

        locks=new Lock[pool_size];
        for(int i=0; i < locks.length; i++)
            locks[i]=new ReentrantLock();
    }
View Full Code Here

Examples of java.util.concurrent.locks.ReentrantLock

        this.arguments = arguments;
        this.environment = environment;
        this.standardOutput = standardOutput;
        this.errorOutput = errorOutput;
        this.standardInput = standardInput;
        this.lock = new ReentrantLock();
        this.stateChange = lock.newCondition();
        this.state = ExecHandleState.INIT;
        executor = new DefaultExecutorFactory().create(String.format("Run %s", displayName));
        shutdownHookAction = new ExecHandleShutdownHookAction(this);
        broadcast = new AsyncListenerBroadcast<ExecHandleListener>(ExecHandleListener.class, executor);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.