Threads Interview Questions
- 0of 0 votes
AnswerWrite an algorithm to avoid and detect deadlock in C++ ?
- lipun4u December 03, 2011 in India
What is Banker's algorithm ?| Report Duplicate | Flag | PURGE
Manhattan associates Developer Program Engineer Threads - 0of 0 votes
AnswerDifference between notify() and notifyAll()
- saurabhsonu001 December 03, 2011 in India| Report Duplicate | Flag | PURGE
Infibeam Software Engineer / Developer Threads - 0of 0 votes
AnswersHow to detect deadlock in threads ?
- lipun4u September 16, 2011 in India
How to prevent deadlock in threads ?| Report Duplicate | Flag | PURGE
Symphony Services Production Engineer Threads - 0of 0 votes
AnswersI have two methods of an object, and they each access a critical section of code. I want to restrict access to the section so that in one method, I allow multiple threads to access the critical section. In the other method, I want only one thread to have access. If a caller calls the second method, it should lock out all clients from accessing the critical section in either of the two functions. Here is the basic structure of the class:
- KrrishDon August 10, 2011
class ClassThatNeedsFixing
{
public:
// Will allow many concurrent threads through, unless there is a
// call to the other method.
void AllowMany() {
// Here is the critical section that must be protected
...
}
// Will lock out any client, including callers to the other method.
void AllowOne() {
// Here is the critical section that must be protected
...
}
private:
// Assume there are members here that need protecting
// above.
...
};
In order to solve this problem, you are provided with two classes: Mutex and Semaphore. They have the standard behavior of the concepts that share their class names. Here are the public interfaces for each of these classes:
class Mutex
{
public:
Mutex();
void Acquire();
void Release();
};
class Semaphore
{
public:
// At it's creation, one can specify the count
// of the semaphore.
Semaphore(unsigned int count);
void Acquire();
void Release();
};
Fix the ClassThatNeedsFixing implementation so that the critical section is protected.
Your solution will be graded on flexibility and robustness (i.e., we should be able to re-use your solution in a generic case and it should be exception safe). You are allowed to create as many classes/objects/templates/etc that you need. Feel free to use the STL if necessary. Document your code as you would for real-world maintainability.| Report Duplicate | Flag | PURGE
Google Developer Program Engineer Threads - 1of 1 vote
Answersresult of this:
- Anonymous August 07, 2011main() { fork(); fork(); fork(); printf("hello\n"); }
| Report Duplicate | Flag | PURGE
C Operating System Threads - 0of 0 votes
AnswersDrawbacks of using mutexes in threads.
- Anonymous July 17, 2011| Report Duplicate | Flag | PURGE
Bloomberg LP Threads - 0of 0 votes
AnswersI have attended SONY interview recently. One of the RTOS question was what is priority inversion?? I answered but he asked why a high priority task is waiting for the low priority task to complete its job instead of preempting it?? I answered in order to avoid starvation..but he told that is not the correct answer...If somebody knows plz help..
- Alex June 19, 2011| Report Duplicate | Flag | PURGE
Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is Deadlock? How to avoid Deadlock?
- Vivek February 12, 2011| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Threads - 0of 0 votes
Answerwhat are threads and multi-threads?
- bk February 07, 2011| Report Duplicate | Flag | PURGE
One97 Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is the difference between a process and a thread?
- Jerry February 01, 2011| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Threads - 0of 0 votes
AnswersA program has two functions 'reader_func' and 'writer_func'. The reader_func reads shared data and contains a critical section. The writer_func writes to shared data and contains a critical section.
Reader threads call reader_func. Writer threads call writer_func.
The condition is multiple reader threads can access the critical section at the same time as long as they don't access the critical section along with a writer. Only a single writer thread can access the critical section, i.e. no reader or other writer threads are allowed.
Give the code segment, add code that uses mutexes that controls access to the critical sections so that the shared data is not corrupted and satisfies the give conditions. You can create as many mutexes and global variables as you want. Don't emphasize too much on syntax as to how to acquire and release locks on mutexes. Just use mutex.acquire() and mutex.release() .
Code segment:
- spookymulder83 December 17, 2010void reader_func() { //critical section } void writer_func() { //critical section }
| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is a deadlock?
- Anonymous October 11, 2010
How can you avoid it?| Report Duplicate | Flag | PURGE
Flipkart Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat are the main concepts in multi threading code?
- Anonymous October 11, 2010| Report Duplicate | Flag | PURGE
Flipkart Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is deadlock and what are the 4 conditions that creates a deadlock?
- Vishal August 03, 2010
Concepts of critical section and how we use lock and unlock resource to access the shared resource?| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer / Developer Threads - 0of 0 votes
AnswersMemory is an array R[1..n]. And a Block is essentially all memory between two indexes i, and j. Now, each application uses some blocks. And blocks can be contained within one another or can be disjoint, but they cannot be intersecting otherwise. So in this scenario, write an algorithm to lock or unlock a block. if a block is locked, none of its child blocks should be allowed to be locked and none of its parent blocks should be allowed to be locked.
- someone June 28, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is the difference between a process and a thread?
- Anonymous June 08, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Threads - 0of 0 votes
AnswersImplement Mutex.
- Anonymous May 20, 2010| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Threads - 0of 0 votes
AnswersImplement a semaphore using a mutex
- raady April 25, 2010| Report Duplicate | Flag | PURGE
Riverbed Software Engineer / Developer Threads - 0of 0 votes
AnswersDifference between a process & thread .If one thread gives a pointer to a variable in its stack to another thread will it be able to access it .Can 2 processes have a shared variable..or is it possible only b/w 2 threads.
- raady April 22, 2010| Report Duplicate | Flag | PURGE
Riverbed Software Engineer / Developer Threads - 0of 0 votes
Answersdifferent between exec and fork. will parent process and child process
- Keyur April 20, 2010
in deadlock if parent is using resource and child will also get same resource ?
what if parent contains two threads ? will child also get 2 threads ? how fork will be thread safe ?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Threads C++ - 0of 0 votes
Answerstested on the concept of Waiting,Notify..
- Sourabh Kapoor April 08, 2010| Report Duplicate | Flag | PURGE
Research In Motion Software Engineer / Developer Threads - 0of 0 votes
Answershow to prevent deadlock.
- Keyur March 31, 2010| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is a Deadlock, can you give some examples of real world scenarios where deadlock happens ?
- dagnihot March 30, 2010
I am trying to merge into a freeway which is completely backed up and cars are moving very slow, is this a deadlock ? If you had to assign a computer science term to this scenarios what would be the closest thing that comes to your mind ?| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer Threads - 0of 0 votes
AnswersGiven a contiguous chunk of a memory, design N queues in it. Make them thread safe.
- AnonymousUser March 28, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Threads - 0of 0 votes
Answersdetecting deadlock
- mojo dojo :) March 19, 2010| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer Threads - 0of 0 votes
AnswersWhat is a deadlock and what are some of the ways to avoid a deadlock?
- aquila.25 February 27, 2010| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Threads