public void Lock() {
		QNode myNode = currNode.get();								//get a new qnode
		AtomicReference<QNode> localQueue = localQueues.get(((TestThread)Thread.currentThread()).getClusterId());

		QNode myPred = null;
		do {
			myPred = localQueue.get();
		} while (!localQueue.compareAndSet(myPred, myNode));
		
		if (myPred != null) {
			boolean iOwnLock = myPred.waitForGrantOrClusterMaster();
			if (iOwnLock) {
				for(int i = 0;i<10;i++){}
				predNode.set(myPred);
				return;
			}
		}
		// I am the cluster master: splice local queue into global queue.
		
		//	System.out.println("cluster master: "+ ((TestThread)Thread.currentThread()).getThreadId());
		for(int i = 0;i<10;i++){}

		QNode localTail = null;
		do {
			myPred = globalQueue.get();
			localTail = localQueue.get();
		} while(!globalQueue.compareAndSet(myPred, localTail));
		
		// inform successor it is the new master
		localTail.setTailWhenSpliced(true);
		
		// wait for predecessor to release lock
		while (myPred.isSuccessorMustWait()) {};
		//for(int i = 0;i<10;i++){}
		// I have the lock. Save QNode just released by previous leader
		predNode.set(myPred);
		return;
	}