NVIDIA Interview Question for Software Engineer / Developers






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

Mutex has ownership, ie. a process that owns the mutex can only lock and release the mutex, also if the process gets killed, the OS releases all the mutexes owned by the process. How do we achieve process ownership by any of the methods mentioned above?

- Prakash March 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i would make use of an atomic instruction like the test_and_set in x86 but instead of keeping the threads spinning and waiting..log them into a queue for both fairness and not wasting CPU cycles..

- Mr.Mackey November 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rather block myself when I fail to get a spinlock and wait on a queue. Periodically, I will poll for the lock and repeat step 1.

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

Use a TSL to set the lock's state. Based on the value returned by the TSL decide whether to block itself or enter the critical region.

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

Q could be a simple FCFS or a thread priority based queue.
Pseudocode:

void mutex_lock_blocking(Mutex* mhandle, Thread* thandle)
{
   spinlock_lock(mhandle->spinlock);
   if(! is_Q_empty(mhandle->queue))
   {
      Q_push(thandle);
      // Blocks thread. Scheduler can schedule threads with runnable == TRUE
      thread->sched_runnable = FALSE;
      spinlock_unlock(mhandle->spinlock);
      // Calls the thread scheduler. Returns only when some other threas sets runnable = TRUE
      // for the current thread.
      scheduler_yield();
   }
   thread->sched_runnable = FALSE;
   Q_push(thandle);
   spinlock_unlock(mhandle->spinlock);

   return;
}

void mutex_unlock(Mutex* mhandle, Thread* thandle)
{
   spinlock_lock(mhandle->spinlock);
   // Remove self from the Q
   Q_remove(thandle);
   // Mark next thread on Q. But do not pop it yet. next_runnable_thandle will resume
   // resume execution just after returning from scheduler_yield() from mutex_lock_blocking
   next_runnable_thandle = Q_get_next();
   next_runnable_thandle->runnable = TRUE;
   spinlock_unlock(mhandle->spinlock);
}

- Anonymous January 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

volatile int lock = 0;

void Critical() {
while (TestAndSet(&lock) == 1);
critical section //only one process can be in this section at a time
lock = 0 //release lock when finished with the critical section
}

- isisme January 27, 2010 | 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