Yahoo Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

To make deadline happen, it must satisfy four conditions:
1. Each resource is available or hold to exactly one process
2. Process currently hold resources can request new resource
3. Don't allow to force process release resource
4. A chain of processes waiting for resources currently hold by another resource.

So break one of these four conditions, there will be no deadlock.

- Silence February 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if you suggest the breaking those conditions, it could be better( ex> to break 4th conditon, notify order of resource holding, and processes must hold resources obey the order, and there's no circular resource holding.)

- Zaphod March 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

don't use threads

- Anonymous March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If one does not used threads how can one achieve concurrency which is vital. Hence the code must do concurrent work and properly synchronize access to data that is shared among threads.

- Singleton July 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Program shows deadlock.

public class Deadlock {

	static Object mutexOne = new Object();
	static Object mutexTwo = new Object();

	public static void main(String[] args) {
		Thread t1 = new Thread(new DeadlockProneOne());
		Thread t2 = new Thread(new DeadlockProneTwo());
		t1.start();
		t2.start();
	}
}

class DeadlockProneOne implements Runnable {

	public void run() {
		// Flip locks
		synchronized (Deadlock.mutexOne) {
			// Do some work
			for (int i = 0; i < 100; i++) {
			}

			synchronized (Deadlock.mutexTwo) {
				// Do some work
				for (int i = 0; i < 100; i++) {
				}
			}
		}
	}

}

class DeadlockProneTwo implements Runnable {

	public void run() {
		// Flip locks
		synchronized (Deadlock.mutexTwo) {
			// Do some work
			for (int i = 0; i < 100; i++) {
			}

			synchronized (Deadlock.mutexOne) {
				// Do some work
				for (int i = 0; i < 100; i++) {
				}
			}
		}
	}

}

Fix:
Make sure code is properly synchronized.

- Singleton July 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Coffman's conditions:
1) Mutual exclusion
2) Hold & wait
3) No preemption
4) Cicular wait

- jzhu May 20, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More