Adobe Interview Question for Software Engineer / Developers






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

public class Semaphore {
private final int MAX_SLOTS = 10;
private int empty_slots = MAX_SLOTS;

public void down() {
synchronized (this) {
while (empty_slots == 0) {
try {
wait();
} catch (InterruptedException ex) {

}
}
empty_slots--;
}
}

public void up() {
synchronized (this) {
if (empty_slots < MAX_SLOTS) {
empty_slots++;
}
notifyAll();
}
}
}

- random May 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Semaphore is having protected non-negative integer value, which control critical section execution by process/threads.

With the below implementation we can control any critical section by issuing with below sequences..

WAIT();
// Start Critical Section...
... do whatever you want to carry out....
// End Critical Section...
SIGNAL();

public void SemaPhore {
  private int mutex = 1;

  public synchronized WAIT() {
     while(mutex == 0) {
       try {
         wait(); // wait till other thread/process notifies it to proceed.
       } catch(InterruptedException e) {
          // keep trying...
       }
     }

     mutex--;
  } 

  public synchronized SIGNAL() {
     mutex++;
     notifyAll(); // notify all the thread 
  } 

}

- MasterSolution June 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

both of these two approaches are too expensive, try one without using lock

- Ryan Zhang August 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I love you
I love you

- Anonymous September 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Anonymous on September 10, 2009

We hate you/spammers
We hate you/spammers
We hate you/spammers

- Anonymous October 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In java concurrent access is managed by synchronized methods or statements.

This question is to test the same...

solution:

//making member static so that synchronization is for class rather than individual instance.

//
private static counter = 0;

public synchronized static void increase(){
	counter++;
}

public synchronized static void decrease(){
	if(counter > 0)
		counter--;	
}
//

// java concurrency mechanism takes care of notifying all the other threads who are waiting to gain the access.

- master December 31, 2009 | 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