Write a custom lock without using synchronization key word.

For Microsoft interview, I am asked to write a custome lock. I have implemented the following.

public class Lock {
	boolean isLoked = false;

	public synchronize void lock() {
		while (isLoked) {
			this.wait();
		}
		isLoked = true;
	}
	
	public synchronize void unlock() {
		isLoked = false;
		this.notify();
	}

}

But now the interviewer wants me to not to use the synchronize keyword. Anyone knows the solution?

Comments (4)